servicestack-razor

ServiceStack ToPostUrl() extension method ignores virtual directories


I'm using ServiceStack.Razor C# in Visual Studio 2015 for a small internal project and am working (learning) from the sample projects. As part of my development, I host all of my websites and apis etc in virtual directories, so rather than

localhost/hello

i have

localhost/SomeProject/hello

The problem is however, that once the razor is being delivered from the virtual directory /SomeProject/ , the ToPostUrl() extension method creates an absolute path and so the logic fails:

<form action="@(new Hello().ToPostUrl())">

results in

<form action="/hello"> 

which breaks the redirect when the form is submitted. What is the correct way to handle this? A virtual directory doesn't seem like a particularly unusual use-case?

Thanks


Solution

  • ServiceStack's Reverse routing only resolves paths from ServiceStack's Route definitions.

    You'll need to include the prefix to any custom paths/virtual directory where ServiceStack is mounted before the route.