在 IIS 中部署 mvc2 应用程序时出错

发布于 2024-10-14 23:23:58 字数 2382 浏览 1 评论 0原文

我们正在 Internet 上的生产环境中的 IIS 上部署基于 MVC2 的应用程序。发生错误,这是引发错误的过程:

  1. 用户单击链接以显示 Web 表单
  2. 用户插入数据。
  3. 用户提交表单。
  4. 应用程序显示错误。它的跟踪显示对象的引用未设置到实例。显然,MVC 的引擎丢失了与模型相关的 HTTP POST 请求数据,因此系统在操作执行过程中的未指定时间为操作的参数分配了 null。

在我们的内网测试环境中,这个问题从未发生过。

这是错误:

// Error
Exception Error: Object reference not set to an instance of an object.
Exception Source: MagaARPIU
Exception Data: System.Collections.ListDictionaryInternal
Exception Trace: at MagaARPIU.Areas.GestionComercial.Controllers
    .ProspectacionController.IngresarEmpresa(InfoEmpresa modelo) 
in C:\Desarrollo\calvarez\codigo\Gacela ARP - Publicaciones\Gacela ARP\Maga\MagaARPIU\Areas\GestionComercial\Controllers\ProspectacionController.cs:line 151 
at lambda_method(Closure , ControllerBase , Object[] ) 
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
at System.Web.Mvc.ControllerActionInvoker
    .InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

// -- ProspectacionController.cs

105        [RolAuthorizationAttribute]
106        public ActionResult IngresarEmpresa()
107        {
108            var modelo = new InfoEmpresa();
                ...
113            modelo.DatosIdentificacion = new DatosIdentificacion();
                ...
137            return View("IngresarEmpresa1", modelo);
                ...
139         }

145        [HttpPost]
146        [RolAuthorizationAttribute]
147        public ActionResult IngresarEmpresa(InfoEmpresa modelo)
148        {
                ...
151            if (!modelo.DatosIdentificacion.Completo)
152            {
                ...
179            }
                ...
305        }

您知道发生了什么以及如何解决这个问题吗?

We are deploying an MVC2 based app on IIS at production environment floating in Internet. An error occurs and this is the process to raise it:

  1. The user clicks on a link to display a web form
  2. The user inserts data.
  3. The user submits the form.
  4. The application shows an error. Its trace shows that a reference for an object is not set to an instance. Apparently MVC's engine loses HTTP POST request data regarding to the model so the system assigns a null for actions's parameter at an unspecified time in the action's execution.

On Testing environment, at our intranet, this problem never had happened.

Here is the error:

// Error
Exception Error: Object reference not set to an instance of an object.
Exception Source: MagaARPIU
Exception Data: System.Collections.ListDictionaryInternal
Exception Trace: at MagaARPIU.Areas.GestionComercial.Controllers
    .ProspectacionController.IngresarEmpresa(InfoEmpresa modelo) 
in C:\Desarrollo\calvarez\codigo\Gacela ARP - Publicaciones\Gacela ARP\Maga\MagaARPIU\Areas\GestionComercial\Controllers\ProspectacionController.cs:line 151 
at lambda_method(Closure , ControllerBase , Object[] ) 
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a() 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) 
at System.Web.Mvc.ControllerActionInvoker
    .InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)

// -- ProspectacionController.cs

105        [RolAuthorizationAttribute]
106        public ActionResult IngresarEmpresa()
107        {
108            var modelo = new InfoEmpresa();
                ...
113            modelo.DatosIdentificacion = new DatosIdentificacion();
                ...
137            return View("IngresarEmpresa1", modelo);
                ...
139         }

145        [HttpPost]
146        [RolAuthorizationAttribute]
147        public ActionResult IngresarEmpresa(InfoEmpresa modelo)
148        {
                ...
151            if (!modelo.DatosIdentificacion.Completo)
152            {
                ...
179            }
                ...
305        }

Do you know what is going on and how to solve this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请恋爱 2024-10-21 23:23:58

从您提供的信息很难说出为什么您的模型在 POST 操作中为空。我只是想知道为什么你的代码看起来不像这样:

[HttpPost]
[RolAuthorizationAttribute]
public ActionResult IngresarEmpresa(InfoEmpresa modelo)
{
    if (ModelState.IsValid)
    {
        // The validation failed => redisplay the view so that the user
        // can fix the errors:
        return View(modelo);
    }
    // at this stage validation passed => do something with the model
    ...
}

就调试你的问题而言,你可能想在你的控制器操作中添加一些日志记录,这将跟踪发送的请求参数并查看丢失的内容。

It is very difficult to say why your model is null in the POST action from the information you provided. I just wonder why doesn't your code look like this instead:

[HttpPost]
[RolAuthorizationAttribute]
public ActionResult IngresarEmpresa(InfoEmpresa modelo)
{
    if (ModelState.IsValid)
    {
        // The validation failed => redisplay the view so that the user
        // can fix the errors:
        return View(modelo);
    }
    // at this stage validation passed => do something with the model
    ...
}

As far as debugging your problem is concerned you probably want to put some logging inside your controller action which would trace the request parameters being sent and see what's missing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文