2014-11-08 3 views
0

У меня есть страница регистрации. он работает на моем локальном компьютере, но после того, как я развернулся на производство. Не удалось получить следующее сообщение об ошибкеasp.net mvc: Error1: Значение не может быть равно

  Server Error in '/' Application. 

      Error1: Value cannot be null. 
      Parameter name: view 

      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

      Exception Details: System.Exception: Error1: Value cannot be null. 
      Parameter name: view 

      Source Error: 

      An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

      Stack Trace: 


      [Exception: Error1: Value cannot be null. 
      Parameter name: view] 
       Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user, String returnUrl) +662 
       lambda_method(Closure , ControllerBase , Object[]) +149 
       System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 
       System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181 
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
       System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56 
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256 
       System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22 
       System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190 
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311 
       System.Web.Mvc.Controller.ExecuteCore() +105 
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88 
       System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34 
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19 
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10 
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31 
       System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
       System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23 
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59 
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172 
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 

Вот мой код, я потратил целый день на его отладочную работу, до сих пор не повезло.

//[ChildActionOnly] 
    public virtual ActionResult Signup(string returnUrl) 
    { 
     return PartialView(MVC.Account.Views._Register, new UserRegisterViewModel()); 
     //return PartialView("_Register", new UserRegisterViewModel()); 
    } 

    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public virtual ActionResult Signup(UserRegisterViewModel user, string returnUrl) 
    { 
     try 
     { 

      if (ModelState.IsValid) 
      { 
       var newUser = _mappingService.Map<UserRegisterViewModel, User>(user); 

       if (newUser == null) 
       { 
        throw new Exception("newUser cannot be null"); 
       } 

       var confirmation = _userService.AddUser(newUser, AccountType.Smoothie); 

       if (confirmation.WasSuccessful) 
       { 
        var userData = _mappingService.Map<User, UserDataDto>(confirmation.Value); 

        if (userData == null) 
        { 
         throw new Exception("userData cannot be null"); 
        } 

        _authenticationService.SetAuthCookie(Response, userData.DisplayName, false, userData); 

        Utilities.SendEmail(ConfigurationManager.AppSettings["EmailReply"], 
             new List<string> {userData.Email}, "Welcome to putastrawinit.com", 
             GetWelcomeEmail()); 

        var redirectUrl = "/home"; 
        if (returnUrl != null && Url.IsLocalUrl(returnUrl)) 
        { 
         redirectUrl = returnUrl; 
        } 


        return Json(new {Success = true, RedirectUrl = redirectUrl}); 
        //return RedirectToAction("Index", "Home", null); 


       } 

       ModelState.AddModelError("", confirmation.Message); 
      } 
     } 
     catch (Exception e) 
     { 
      throw new Exception("Error1: " + e.Message); 
     } 

     var errors = from value in ModelState.Values 
        from error in value.Errors 
        select new { error.ErrorMessage }; 

     //throw new Exception("Errors: " + errors.ToString()); 

     return Json(new { Success = false, ErrorMessages = errors }); 
    } 

страница регистрации вверх.

  @model Smoothie.Domain.ViewModels.UserRegisterViewModel 
      @using (Ajax.BeginForm("Signup", "Account", new AjaxOptions { OnSuccess = "onSignupSuccess", OnFailure = "onSignupFailure" })) 
      { 

       @Html.AntiForgeryToken() 
       @Html.Hidden("returnUrl", null, new { value = @Request.QueryString["returnUrl"] })  
       <div class="signupForm"> 
        <div>@Html.ValidationSummary("", new { @id = "signupSummary" })</div> 
        <div class="row"> 
         <label for="Email"> 
          Display Name:</label> 
         @Html.EditorFor(m => m.DisplayName) 
        </div> 
        <div class="row"> 
         <label for="Email"> 
          Email Address:</label> 
         @Html.TextBoxFor(m => m.Email, new {@class = "text-box", autocomplete = "off" }) 
        </div> 
        <div class="row"> 
         <label for="Password"> 
          Password:</label> 
         @Html.TextBox("Password", null, new { @class = "registerPassword text-box", type = "password", autocomplete = "off" }) 
        </div> 
        <div class="row"> 
         <label> 
          &nbsp;</label> 
         <div class="registerChecker"> 
         </div> 
        </div> 
        <div class="row"> 
         <label> 
          &nbsp;</label> 
         <input type="image" src="@Links.Content.images.btn_sign_up_png" style="width: 91px; height: 33px;" value="Create" /> 
        </div> 
       </div> 
      } 

Это ViewModel.

  using System.ComponentModel.DataAnnotations; 

      namespace Smoothie.Domain.ViewModels 
      { 
       public class UserRegisterViewModel 
       { 
        [Required(ErrorMessage = "Email is required")] 
        [StringLength(255, ErrorMessage = "Email must be 50 characters or fewer")] 
        [RegularExpression(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", ErrorMessage = "Your Email address is invalid")] 
        public string Email { get; set; } 

        [Required(ErrorMessage = "Display name is required")] 
        [StringLength(25, MinimumLength = 2, ErrorMessage = "Display name must be between 2 and 25 characters")] 
        public string DisplayName { get; set; } 

        [DataType(DataType.Password)] 
        [Required(ErrorMessage = "Password is required")] 
        [StringLength(25, MinimumLength = 8, ErrorMessage = "Password must be between 8 and 25 characters")] 
        public string Password { get; set; } 
       } 
      } 

это новая трассировка стека после того, как я удалил try catch из кода.

 Value cannot be null. 
     Parameter name: view 

     Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

     Exception Details: System.ArgumentNullException: Value cannot be null. 
     Parameter name: view 

     Source Error: 

     An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

     Stack Trace: 


     [ArgumentNullException: Value cannot be null. 
     Parameter name: view] 
      System.Web.Mvc.ViewContext..ctor(ControllerContext controllerContext, IView view, ViewDataDictionary viewData, TempDataDictionary tempData, TextWriter writer) +205 
      Smoothie.Web.Controllers.AccountController.GetWelcomeEmail() +178 
      Smoothie.Web.Controllers.AccountController.Signup(UserRegisterViewModel user) +288 
      lambda_method(Closure , ControllerBase , Object[]) +106 
      System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14 
      System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +181 
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27 
      System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +56 
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +256 
      System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +22 
      System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +190 
      System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +311 
      System.Web.Mvc.Controller.ExecuteCore() +105 
      System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +88 
      System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10 
      System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +34 
      System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +19 
      System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +10 
      System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55 
      System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +31 
      System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7 
      System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23 
      System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59 
      System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9 
      System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9690172 
      System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155 
+0

Не уверен, что вы подразумеваете под мои маршруты. маршрут:/Учетная запись/Регистрация, я также публикую страницу просмотра внизу, надеюсь, это помогает. – qinking126

+0

какая линия 662? – Steve

+0

@Steve, строка 662 публичная виртуальная регистрация ActionResult (UserRegisterViewModel пользователь, строка returnUrl) – qinking126

ответ

2

Основываясь на последнем стеке вызовов, это выглядит как точка зрения отсутствует GetWelcomeEmail(), который вызывает view утратившими в конструкторе ViewContexts.

+0

Я попробовал их как на своем локальном компьютере, они оба работают. затем попробовали их обоих в производстве, они оба не работали. должно быть что-то другое. – qinking126

+0

не уверен, что вы подразумеваете под мои маршруты. маршрут:/Учетная запись/Регистрация, я также публикую страницу просмотра внизу, надеюсь, это помогает. – qinking126

+0

@feelexit - Возможно, стоит удалить эти старые комментарии, поскольку они предназначены для ответа, который я ранее размещал. – webnoob

Смежные вопросы