ServiceStack self-host workaround for VirtualPathUtility exception.
If you're self-hosting recent versions of ServiceStack (3.9.45+) and serving Razor views, you'll notice that @href (which is a wrapper around Url.Content) fails with app-relative paths that start with "~/". Add the following to your startup code to work around it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var domain = Thread.GetDomain(); // or AppDomain.Current | |
domain.SetData(".appDomain", "yep"); | |
domain.SetData(".appVPath", "/"); | |
domain.SetData(".appPath", domain.BaseDirectory); | |
if (String.IsNullOrWhiteSpace(domain.GetData(".appId") as string)) | |
{ | |
domain.SetData(".appId", "1"); | |
} | |
if (String.IsNullOrWhiteSpace(domain.GetData(".domainId") as string)) | |
{ | |
domain.SetData(".domainId", "1"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Aaron,
Thx for this info, it turns out this was the cause of Razor not working too well on Mono/HttpListener, so I've now baked it in to v3.9.48.
I pre-populate this info by default on HttpListenerBase.SetAppDomainData which can also be overridden if anyone doesn't like this default behavior.
https://github.com/ServiceStack/ServiceStack/blob/85b45e146a1433cfa79af572c45c3fc744de787a/src/ServiceStack/WebHost.Endpoints/Support/HttpListenerBase.cs#L96-L111