ServiceStack period in route path causes 404 error

I have a route like:

[Route("/usergroup/{User}/{Group}", "GET")] 

The problem is that {User} has a special character (for example, a period), the path is not evaluated properly. How to code this if I check the request manually?

 /usergroup/joe.smith/group1 of course doesn't work /usergroup/joe%2Esmith/group1 doesn't work either 

What is the trick here?

(UPDATE) This looks like some special characters. I can use% 2D (-), but I can not use% 2E (.).

(UPDATE 2) This seems more sinister than that. This only comes from the ASP.Net Development server running Visual Studio.

(UPDATE 3) It makes it painfully debug. In principle, the route route cannot contain a period, or I get "Handler for request not found" 404.

Actually it looks like ServiceStackHttpHandlerFactory (3.9.59) throws the error found.

+7
servicestack
source share
1 answer

I am sure that this is the case when Visual Studio Development Server does not act as a "real" IIS. I just experienced this myself:

  • VS 2012, created a new empty ASP.NET project
  • Used by NuGet to import a startup template for ServiceStack 3.9.59.0
  • created a service and DTO based on your case
  • press F5 - run on localhost
  • /usergroup/joe.schmoe/mygroup/- this works with IISExpress - the route is found and correctly returns the result
  • for using "Visual Studio Development Server"
  • F5, run / usergroup / joe.schmoe / mygroup / again
  • Route Error - "Request handler not found:"

The problem will disappear if you change the properties of the project website and check the box "Use IIS Express" instead of "Visual Studio Development Server".

Cases of using IIS Express are explained here.

I also found another SO answer that is similar to the case. Fortunately, the answer there contains a bad link link, but quotes the actual text.

This is the code I used:

 public class UserGroupService : Service { public object Any(UserGroupRequest request) { return new UserGroup { User = "Got: " + request.User, Group = "Got: " + request.Group, }; } } [Route("/usergroup/{User}/{Group}", "GET")] public class UserGroupRequest { public string User { get; set; } public string Group { get; set; } } public class UserGroup { public string User { get; set; } public string Group { get; set; } } 

Update : I found a good link to the ee941656 link

If you create a file system website in Visual Studio 2010 and the website is located in a folder containing a period (.) In the folder name, URL routing will not work reliably. HTTP Error 404 is returned from some virtual paths. This is because Visual Studio 2010 starts the Visual Studio Development Server (Cassini) using the wrong path for the root virtual directory.

There are 3 workarounds, and only "using IIS instead of Cassini" works.

+5
source share

All Articles