Skip to content

Instantly share code, notes, and snippets.

Created May 28, 2013 18:15
What would you like to do?
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.
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");
Copy link

mythz commented May 29, 2013

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment