IIS redirect issue on .NET 4.8 and Servicestack 5.9

I just upgraded my project (ASP.NET Web with Razor - No MVC) to .NET 4.8 and Servicestack 5.9 but it stopped working when I run it on IIS.

It works fine on IIS Express.

My IIS path is “http://localhost/ABC” and it works fine if I directly type “http://localhost/ABC/login” but if I type “http://localhost/ABC” into the url it gets changed to “http://localhost/ABC/ABC/login?redirect=http%3A%2F%2Flocalhost%2FABC%2FABC%2Flogin%3Fredirect%3Dhttp…” with an message “HTTP 404”.

My question is why does the extra “/ABC” get added to the URL?

VS: 2017
.NET Framework: 4.8
ServiceStack Version: 5.9
OS: Windows 10

It’s not resolving the correct baseUrl, you can override the BaseUrl resolution by overriding GetBaseUrl(IRequest) in your AppHost, you can also specify the URL to use in Config.WebHostUrl. e.g:

SetConfig(new HostConfig { WebHostUrl = "http://localhost/ABC" } );

Can you post the output of ?debug=requestinfo, e.g. for http://localhost/ABC/metadata?debug=requestinfo

Also what version did you upgrade from where the behavior was different?

I upgraded from ServiceStack 5.8 to 5.9 and .NET 4.5 to 4.8.

Anyways, I was able to fix the issue with a simple code change.

Before my upgrade this is how I was setting HtmlRedirect:

Plugins.Add(new AuthFeature(() => new AppUserSession(),
new IAuthProvider {
new CustomCredentialsAuthProvider(),
new CustomBasicAuthProvider()
})
{ HtmlRedirect = VirtualPathUtility.ToAbsolute(“~/login”) });

It started working after I removed “~” from HtmlRedirect:

Plugins.Add(new AuthFeature(() => new AppUserSession(),
new IAuthProvider {
new CustomCredentialsAuthProvider(),
new CustomBasicAuthProvider()
})
{ HtmlRedirect = VirtualPathUtility.ToAbsolute(“/login”) });

Just in case you need the debug info:

{
“usage”: “append ‘?debug=requestinfo’ to any querystring. Optional params: virtualPathCount”,
“host”: “_v5.90_ABC ASP.NET Host”,
“hostType”: “ASP.NET (AppHostBase)”,
“startedAt”: “2020-06-26 03:51:11”,
“date”: “2020-06-26 03:51:34”,
“serviceName”: “ABC ASP.NET Host”,
“userHostAddress”: “::1”,
“httpMethod”: “GET”,
“pathInfo”: “/metadata”,
“originalPathInfo”: “/metadata”,
“stripApplicationVirtualPath”: false,
“getLeftPath”: “http://localhost”,
“path”: “/ABC/metadata”,
“getPathUrl”: “http://localhost/ABC/metadata”,
“absoluteUri”: “http://localhost/ABC/metadata?debug=requestinfo”,
“applicationBaseUrl”: “http://localhost/ABC”,
“resolveAbsoluteUrl”: “http://localhost/ABC/resolve”,
“applicationPath”: “/ABC”,
“applicationVirtualPath”: “/ABC”,
“virtualAbsolutePathRoot”: “/”,
“virtualAppRelativePathRoot”: “/”,
“rootDirectoryPath”: “C:\VS Projects\Repos\ABC\ABC.Web\wwwroot”,
“contentRootDirectoryPath”: “C:\VS Projects\Repos\ABC\ABC.Web\wwwroot”,
“currentDirectory”: “c:\windows\system32\inetsrv”,
“handlerFactoryArgs”: “GET|/ABC/metadata|C:\VS Projects\Repos\ABC\ABC.Web\metadata”,
“rawUrl”: “/ABC/metadata?debug=requestinfo”,
“contentType”: “”,
“status”: 0,
“contentLength”: 0,
“headers”: {
“Connection”: “keep-alive”,
“Accept”: “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”,
“Accept-Encoding”: “gzip, deflate, br”,
“Accept-Language”: “en-US,en;q=0.9”,
“Cookie”: “__RequestVerificationToken_L1BGTw2=AQD9C1Kr_TPyVaF5Ek6lOBkB0; __RequestVerificationToken_L0RRTUM1=AWE642VcqGi184VEeXqgO_AB0; __RequestVerificationToken_L0RhdGFBY2N1cmFjeQ2=AZ0egto9-zMzvpusVwq4plYB0; __RequestVerificationToken_L0NSTQ2=AZjb5cJ3tOfnYZ7zNPiPs88B0; __RequestVerificationToken_L1N0b2NrVHJhY2tlckJpbw2=ARJujV0k34Q6mU0NFYpoTtMB0; ss-opt=temp; _ga=GA1.1.447995829.1553144764; InvoiceDateFilter=4; __RequestVerificationToken_L3BmbzI1=ARZFa0t5pBWd33his0xVLgEB0; EmailSearchDateFilter=3; BatchSearchDateFilter=3; __RequestVerificationToken_L1JN0=ARciWV405qWptET_fXMoDjwB0; __RequestVerificationToken=AWOhvK_W0pyFq1MlfPB7nOwB0; ss-pid=XXXX; ss-id=XXXX”,
“Host”: “localhost”,
“User-Agent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36”,
“Upgrade-Insecure-Requests”: “1”,
“Sec-Fetch-Site”: “none”,
“Sec-Fetch-Mode”: “navigate”,
“Sec-Fetch-Dest”: “document”
},
“queryString”: {
“debug”: “requestinfo”
},
“formData”: {},
“acceptTypes”: [
“text/html”,
“application/xhtml+xml”,
“application/xml;q=0.9”,
“image/webp”,
“image/apng”,
/;q=0.8”,
“application/signed-exchange;v=b3;q=0.9”
],
“operationName”: “/ABC/metadata”,
“responseContentType”: “text/html”,
“requestAttributes”: “Localhost, InSecure, HttpGet”,
“ipv4Addresses”: “XXXX”,
“ipv6Addresses”: “XXXXX”,
“logonUserInfo”: {
“Name”: “NT AUTHORITY\IUSR”,
“AuthenticationType”: “”,
“IsAuthenticated”: “False”,
“IsAnonymous”: “False”,
“IsGuest”: “False”,
“IsSystem”: “False”,
“Groups”: “S-1-1-0, S-1-5-32-545, S-1-2-1, S-1-5-11, S-1-5-15, S-1-2-0”,
“User”: “S-1-5-17”,
“User.AccountDomainSid”: “null”,
“User.IsAccountSid”: “False”
},
“debugString”: “System.Web.HttpRequest|System.Web.HttpResponse”,
“pluginsLoaded”: [
“HtmlFormat”,
“CsvFormat”,
“PredefinedRoutesFeature”,
“MetadataFeature”,
“NativeTypesFeature”,
“HttpCacheFeature”,
“RequestInfoFeature”,
“SpanFormats”,
“SvgFeature”,
“ValidationFeature”,
“SessionFeature”,
“RazorFormat”,
“MiniProfilerFeature”,
“HotReloadFeature”,
“RequestLogsFeature”,
“SessionFeature”,
“AuthFeature”
],
“startUpErrors”: ,
“asyncErrors”: ,
“lastRequestInfo”: {
“handlerType”: “RequestInfoHandler”,
“operationName”: “RequestInfoHandler”,
“pathInfo”: “”
},
“stats”: {
“RawHttpHandlers”: “4”,
“PreRequestFilters”: “2”,
“RequestBinders”: “0”,
“GlobalRequestFilters”: “2”,
“GlobalRequestFiltersAsync”: “1”,
“GlobalResponseFilters”: “1”,
“GlobalResponseFiltersAsync”: “1”,
“CatchAllHandlers”: “4”,
“Plugins”: “17”,
“ViewEngines”: “1”,
“RequestTypes”: “169”,
“ResponseTypes”: “69”,
“ServiceTypes”: “23”,
“RestPaths”: “187”,
“ContentTypes”: “6”,
“EnableFeatures”: “All”,
“VirtualPathProvider”: “[MemoryVirtualFiles: /], [FileSystemVirtualFiles: C:\VS Projects\Repos\ABC\ABC.Web\wwwroot], [ResourceVirtualFiles: ABC.Web], [ResourceVirtualFiles: ServiceStack]”
},
“virtualPathProviderFiles”:
}