Problem
I am currently building a helper for ASP.net MVC 3 and am running into a problem considering the UrlHelper.Action() method. Every request except for the first one (after the application start) the following code throws a NullReferenceException.
var src = htmlHelper.Url().Action("Css", "Asset", options);
Relevant Stack
System.Web.HttpServerVarsCollection.Get(String name) +8740566
System.Web.Mvc.UrlRewriterHelper.WasThisRequestRewritten(HttpContextBase httpContext) +42
System.Web.Mvc.UrlRewriterHelper.WasRequestRewritten(HttpContextBase httpContext) +23
System.Web.Mvc.PathHelpers.GenerateClientUrlInternal(HttpContextBase httpContext, String contentPath) +163
System.Web.Mvc.PathHelpers.GenerateClientUrl(HttpContextBase httpContext, String contentPath) +63
System.Web.Mvc.UrlHelper.GenerateUrl(String routeName, String actionName, String controllerName, RouteValueDictionary routeValues, RouteCollection routeCollection, RequestContext requestContext, Boolean includeImplicitMvcValues) +150
System.Web.Mvc.UrlHelper.Action(String actionName, String controllerName, Object routeValues) +55
Possible Cause
I use a lib called AttributeRouting which I installed through nuget and thought this might cause the problem but removing the reference has no effect.
Because it does work the first request but fails for every request after that I have a feeling it has something to do with code that runs at the application start but should run at request start or that certain variables/objects aren't persisted over the requests.
Extra Info
htmlHelper.Url() is the following extention method.
public static UrlHelper Url(this HtmlHelper helper)
{
return new UrlHelper(helper.ViewContext.RequestContext);
}