Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack period in route path causes 404 error

Tags:

servicestack

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.

like image 530
LiteWait Avatar asked Sep 09 '13 12:09

LiteWait


1 Answers

I'm fairly certain this is a case of Visual Studio Development Server not acting like 'real' IIS. I just tested this myself:

  • VS 2012, created new empty ASP.NET project
  • Used NuGet to import Starter Template for ServiceStack 3.9.59.0
  • created a service and DTOs based on your case
  • press F5 - run on localhost
  • /usergroup/joe.schmoe/mygroup/ - this works with IISExpress - route is found and returns output correctly
  • switch to use "Visual Studio Development Server"
  • F5, run /usergroup/joe.schmoe/mygroup/ again
  • Route fails - "Handler for Request not found:"

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.

like image 63
Raul Nohea Goodness Avatar answered Oct 04 '22 19:10

Raul Nohea Goodness