問題
私は現在、ASP.net MVC 3 のヘルパーを構築しており、UrlHelper.Action() メソッドに関する問題に直面しています。最初のリクエスト (アプリケーションの開始後) を除くすべてのリクエストは、次のコードで NullReferenceException をスローします。
var src = htmlHelper.Url().Action("Css", "Asset", options);
関連スタック
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
考えられる原因
ナゲットを介してインストールした AttributeRouting というライブラリを使用していますが、これが問題を引き起こす可能性があると考えましたが、参照を削除しても効果はありません。
最初のリクエストでは機能しますが、その後のすべてのリクエストで失敗するため、アプリケーションの開始時に実行されるがリクエストの開始時に実行する必要があるコードと関係があるか、特定の変数/オブジェクトがリクエスト間で永続化されていないと感じています.
追加情報
htmlHelper.Url() は以下の拡張メソッドです。
public static UrlHelper Url(this HtmlHelper helper)
{
return new UrlHelper(helper.ViewContext.RequestContext);
}