2009-04-27 4 views
1

미리 사과하겠습니다. ASP.NET과 MVC를 처음 사용하고 아직 내부 작업과 작업 흐름을 파악하지 못했습니다. OpenID 지원을 받기 위해 개발중인 사이트에 ASP.NET MVC Membershp Starter 키트를 통합하려고합니다.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에 대한 호출 ("오픈 ID", "로그인")는 예외를 발생 호이다. 여기에 호출 스택의 :

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이 null이고 요청 방법이 "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 vesion이지만 ASP.NET MVC v1.0의 경우 Microsoft.Web.Mvc.dll보다 오래된 버전입니다. Microsoft.Web.Mvc.dll there의 마지막 버전을 다운로드 할 수 있습니다.

+0

넵. 감사. –

1

이 질문에 대한 응답이 거의 없으므로 OpenID를 ASP.NET MVC에 통합하기위한 대안을 찾기 시작했습니다. 나는 RPXNow에 대한 좋은 .NET 및 MVC 래퍼 인 RPXLib을 찾았습니다. 이것은 여러 공급 업체의 OpenID 로그인에 대한 웹 서비스 방식입니다.

openid 자격 증명과 로컬 프로필간에 매핑 코드를 작성해야하기 때문에 완벽한 솔루션은 아니지만 내 요구 사항만으로 충분합니다.

null 참조 예외가 발생하는 Html.Form("controller", "action")의 원래 문제를 해결하는 데 여전히 관심이 있습니다. 같은 결과를 가진 제네릭 버전을 사용해 보았습니다 : Html.Form<Controller>(c => c.Action()).

1

미리보기, 베타 또는 RC가 아닌 ASP.NET MVC v1.0을 사용하고 있습니까? v1.0에는 Html.Form이없고 Hrml.BeginForm 만 존재합니다. ASP.NET MVC v1.0 소스를 살펴보면 Form 메서드는 없지만 System.Web.Mvc.Html.FormExtensions 클래스의 BeginForm 만

+0

MVC 1.0에서는 실제로 * does *가 Html.Form 확장 메서드 인 것처럼 보입니다. Microsoft.Web.Mvc.FormExtensions 정적 메서드 클래스를 참조하십시오. "서식"에는 7 가지의 과부하가 있습니다. 그러나 FormBegin은 흥미로운 것으로 들립니다. 나는 그것을 볼 것이다. –

+0

나는 이전 버전의 Microsoft.Web.Mvc.dll을 사용하고 있다고 생각합니다. –

1

다른 모든 메서드가 실패한 경우에도 ASP.NET MVC source을 다운로드 할 수 있습니다. 프로젝트에 추가하고 디버깅하십시오. 조금 더 노력했지만 실제로는 두려운 부분에서 무엇이 잘못 될지 파악하는 데 도움이됩니다.