I have a route like:
[Route("/usergroup/{User}/{Group}", "GET")]
The problem is when there is a special character (say period) in the {User} the path is not evaluated properly. How should this be encoded if I am testing the request by hand?
/usergroup/joe.smith/group1 of course doesn't work
/usergroup/joe%2Esmith/group1 doesn't work either
What's the trick here?
(UPDATE) This only seems to happen with certain special characters. I can use %2D ( - ) but I can't use %2E ( . ).
(UPDATE 2) This seems more sinister than that. This only appears to happen against the ASP.Net Development server launched by Visual Studio.
(UPDATE 3) This makes it a pain to debug. Basically the route path can not contain a period or I get "Handler for Request not found" 404.
Actually it appears ServiceStackHttpHandlerFactory (3.9.59) is throwing the not found error.
I'm fairly certain this is a case of Visual Studio Development Server not acting like 'real' IIS. I just tested this myself:
The problem will go away if you edit your project Web properties and check "Use IIS Express" instead of "Visual Studio Development Server".
The cases to use IIS Express are explained here
I also found another SO answer which is a similar case. Luckily, the answer there contains a bad link reference, 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 reference ee941656
If you create a file system Web site in Visual Studio 2010 and the Web site is in a folder that contains a dot (.) in the folder name, URL routing will not work reliably. An HTTP 404 error is returned from some virtual paths. This occurs because Visual Studio 2010 launches the Visual Studio Development Server (Cassini) using an incorrect path for the root virtual directory.
There are 3 workarounds, and only the "use IIS instead of Cassini" workaround seems to work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With