I have a ASP.NET Web Site using ServiceStack, The site has index.html page which is supposed to be the default page.
When I run it under IIS Express and the application is at the site root, it works OK.
However when I run it under IIS and provide virtual dir name without trailing slash, the application does not work since Web Server returns directly page content instead of HTTP 302 with redirection to URL with / at the end and relative paths in the page resolved incorrectly (on the web server root level instead of app virt dir).
This works fine without ServiceStack with pure ASP.NET
With SS 4.038 I managed to bypass this using DefaultRedirectPath = “/index.html”, however after upgrade to 4.0.50 it does not work anymore (I also installed ServiceStack.Razor, but I do not think it is relevant).
I want to use it as default document, but it should not be returned for request http://sever/dir
Such request should return HTTP 302 with redirection URL http://sever/dir/ and that URL should return the document.
This is host-specific where some ASP.NET hosts will redirect directories (i.e. before it reaches ServiceStack).
You can have ServiceStack do this in your AppHost with:
RawHttpHandlers.Add(RedirectDirectory);
Which registers a custom http handler that will check every request to ensure requests to directories have a / suffix otherwise will automatically redirect.
Although I’d recommend that you always link to the url with the / suffix and save the latency of a redirect, e.g: http://server/dir/
As I said earlier it’s not ServiceStack that handles auto directory redirects for ASP.NET websites, its specific to the ASP.NET host.
The code I’ve provided is how you tell ServiceStack it should add the overhead of checking every request. But if the ASP.NET host already does this you don’t want to add the overhead of checking every request again - which is why it’s opt-in.
would solve this issue, but here I have another problem:
I tried to add ServiceStack.Razor and renamed my page index.html to index.cshtml. Now it works under IISExpress in root dir, but fails under non-root Web directory on redirecting the URL to http://localhost/index. I read that this is “Pretty urls by default” feature of Razor, but how I get rid of it? This redirected naturally fails with 404, so the page is not dispalyed.
Going to need to see a repro of this to understand and identify what the exact issue is. Can you provide a small standalone project that has the issue (e.g. on GitHub).
FYI: If you want to post code or xml in Markdown you need to escape it, either with triple backticks, e.g:
```
You can escape code or xml here
```
Or by just indenting the code or xml 4 spaces in between new lines, e.g: