Skip to content

Instantly share code, notes, and snippets.

@aaronlerch
Created May 28, 2013 18:15
Show Gist options
  • Select an option

  • Save aaronlerch/5664860 to your computer and use it in GitHub Desktop.

Select an option

Save aaronlerch/5664860 to your computer and use it in GitHub Desktop.
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");
}
@mythz

mythz commented May 29, 2013

Copy link
Copy Markdown

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

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