2009-04-27 10 views
1

私は前もってお詫びします。私はASP.NETとMVCを初めて使用していますが、内部的な操作や操作の流れはまだありません。私はASP.NET MVC Membershp Starterキットを私がOpenIDサポートを得るために開発しているサイトに統合しようとしています。MVCメンバーシップ(OpenID)コントローラのASP MVC null参照例外

私はいくつかの問題を解決しましたが、私はどこから取得し続けるnull参照例外を探し始めるのか分かりません。ここで流れです:

  1. ユーザーが
  2. MVC MembershipAdministrationControllerが適切に発射されるページの「ログイン」をクリックします。現在ログインしているユーザーがいないことを検出し、ログインフォーム(Login.aspx)で応答します。
  3. このフォームのレンダリング中にnull参照例外がスローされます。具体的には、例外をスローセクションがある:

    <% using(Html.Form("OpenID", "Login")){ %> 
        <fieldset class="MvcMembership"> 
        <legend>Login</legend> 
        <div><label for="openid_identifier">OpenID Url:</label> <% =Html.TextBox("openid_identifier")%></div> 
        <div><% =Html.SubmitButton("submit", "Login", new { onclick = "return starterKit_mvc_membership_validateOpenIdLogin();" })%></div> 
        </fieldset> 
    <% } %> 
    

Html.Form(「OpenIDの」、「ログイン」)へのコールは例外をスローコールです。ここでは、コールスタックがあります:

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.NullReferenceException: Object reference not set to an instance of an object. 
    at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() 
    at System.Web.Routing.ParsedRoute.Bind(RouteValueDictionary currentValues, RouteValueDictionary values, RouteValueDictionary defaultValues, RouteValueDictionary constraints) 
    at System.Web.Routing.Route.GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) 
    at System.Web.Routing.RouteCollection.GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) 
    at Microsoft.Web.Mvc.FormExtensions.Form(HtmlHelper helper, String controllerName, String actionName, FormMethod method, IDictionary`2 htmlAttributes) 
    at Microsoft.Web.Mvc.FormExtensions.Form(HtmlHelper helper, String controllerName, String actionName) 
    at ASP.views_openid_login_aspx.__RenderopenIdLoginContent(HtmlTextWriter __w, Control parameterContainer) in d:\Data\Personal\purplemartin.tv\mvc\MvcMembership\Views\OpenID\Login.aspx:line 15 
    at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) 
    at System.Web.UI.Control.Render(HtmlTextWriter writer) 
    at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) 
    at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Data\Personal\purplemartin.tv\mvc\MvcMembership\Views\Shared\Site.Master:line 46 
    at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) 
    at System.Web.UI.Control.Render(HtmlTextWriter writer) 
    at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) 
    at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
    at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) 
    at System.Web.UI.Page.Render(HtmlTextWriter writer) 
    at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) 
    at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) 
    at System.Web.UI.Control.RenderControl(HtmlTextWriter writer) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    --- End of inner exception stack trace --- 
    at System.Web.UI.Page.HandleError(Exception e) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
    at System.Web.UI.Page.ProcessRequest() 
    at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) 
    at System.Web.UI.Page.ProcessRequest(HttpContext context) 
    at ASP.views_openid_login_aspx.ProcessRequest(HttpContext context) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\cada2385\9a6742fc\App_Web_zl9plrr2.1.cs:line 0 
    at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) 
    at System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context, ViewPage page) 
    at System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) 
    at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) 
    at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass11.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) 
    at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 
    at System.Web.Mvc.Controller.ExecuteCore() 
    at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
    at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) 
    at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) 
    at System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) 
    at System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

要求されたとして、ここでは、コントローラは次のようになります。

[HandleError(ExceptionType = typeof(OpenIdException))] 
    [HandleError(ExceptionType = typeof(System.Net.WebException))] 
    public virtual ActionResult Login(string openid_identifier) 
    { 
     //### set page title & declare variables 
     ViewData["Title"] = "Login via OpenID"; 
     var errors = new List<string>(); 
     var rememberMe = false; 
     var openid = new OpenIdRelyingParty(); 

     //### stage 1: display login form to user 
     if(openid.Response == null && Request.HttpMethod != "POST") 
      return View(); 

明らかに、これは完全なコントローラではないが、これは最初の時間を実行しているすべてであります(ログインフォームがレンダリングされるとき)。最初にopenid.Responseがヌルで、要求メソッドが"POST"です。

どこから問題が発生しますか?ルーティングと何か関係があるようですが、わかりません。

+0

コントローラのコードはどのように見えますか? –

+0

メインの質問にコントローラ(関連部分)を追加しました。探してくれてありがとう。 –

答えて

1

Simon、「Microsoft.Web.Mvc.FormExtensions」ではなく「System.Web.Mvc.Html.FormExtensions」を実際に意味しましたか? 'Microsoft.Web.Mvc.FormExtensions'クラス(http://aspnet.codeplex.com/SourceControl/changeset/view/22929#266407)がありますが、Formメソッドはありません。たぶん古いバージョンのMicrosoft.Web.Mvc.dllを使用していますか? ReflectorでMicrosoft.Web.Mvc.dllを開きます - 私のマシンでは、Microsoft.Web.Mvc.dllにバージョン1.0.0があります。0とがある4つの方法:

public static MvcForm BeginForm<TController>(this HtmlHelper helper, Expression<Action<TController>> action) where TController: Controller; 
public static MvcForm BeginForm<TController>(this HtmlHelper helper, Expression<Action<TController>> action, FormMethod method) where TController: Controller; 
public static MvcForm BeginForm<TController>(this HtmlHelper helper, Expression<Action<TController>> action, FormMethod method, IDictionary<string, object> htmlAttributes) where TController: Controller; 
public static MvcForm BeginForm<TController>(this HtmlHelper helper, Expression<Action<TController>> action, FormMethod method, object htmlAttributes) where TController: Controller; 

宣言型:Microsoft.Web.Mvc.FormExtensions

アセンブリ:Microsoft.Web.Mvc、バージョン= 1.0.0.0

更新:

私はASP.Net MVC Membership Starter Kit Preview 5 (0.5)をダウンロードしました。 binフォルダのMicrosoft.Web.Mvc.dllのバージョンは1.0.0.0ですが、ASP.NET MVC v1.0の場合はMicrosoft.Web.Mvc.dllより古いです。 Microsoft.Web.Mvc.dll thereの最新バージョンをダウンロードできます。

+0

Yup ...ベータ版リリースとなりました。ありがとう。 –

1

私はこの質問に対してほとんど反応がなかったので、私はOpenIDをASP.NET MVCに統合するための選択肢を検討し始めました。私はRPXLibを見つけました。これは、RPXNowの.NETとMVCの素晴らしいラッパーです。これは、複数のベンダからのOpenIDログインへのWebサービスアプローチです。

openid資格とローカルプロファイルの間にマッピングコードを書く必要があるので、これは完璧な解決策ではありませんが、私のニーズには十分です。

私はまだHtml.Form("controller", "action")のヌル参照例外を投げて元の問題を解決することに興味があります。私は同じ結果を持つ汎用バージョンを使用しようとしました:Html.Form<Controller>(c => c.Action())

1

ASP.NET MVC v1.0(プレビュー、ベータまたはRCではなく)を使用していますか? v1.0ではHtml.Formはなく、Hrml.BeginFormだけであるようです。 ASP.NET MVC v1.0ソースを見ると、Formメソッドはありませんが、System.Web.Mvc.Html.FormExtensionsクラスのBeginFormのみです

+0

実際にMVC 1.0ではHtml.Form拡張メソッドのように見えます。 Microsoft.Web.Mvc.FormExtensions静的メソッドクラスを参照してください。 "Form"には7つのオーバーロードがあります。しかしFormBeginは興味深いように聞こえる。私はそれを見ます。 –

+0

私はあなたが古いバージョンのMicrosoft.Web.Mvc.dllを使用していると思います –

1

他のすべてが失敗した場合でも、ASP.NET MVC sourceをダウンロードして接続できますプロジェクトに追加してデバッグします。もう少し努力していますが、実際に何がうまくいかないかを理解するのに役立ちます。