在 IIS 中部署 mvc2 应用程序时出错
我们正在 Internet 上的生产环境中的 IIS 上部署基于 MVC2 的应用程序。发生错误,这是引发错误的过程:
- 用户单击链接以显示 Web 表单
- 用户插入数据。
- 用户提交表单。
- 应用程序显示错误。它的跟踪显示对象的引用未设置到实例。显然,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:
- The user clicks on a link to display a web form
- The user inserts data.
- The user submits the form.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从您提供的信息很难说出为什么您的模型在 POST 操作中为空。我只是想知道为什么你的代码看起来不像这样:
就调试你的问题而言,你可能想在你的控制器操作中添加一些日志记录,这将跟踪发送的请求参数并查看丢失的内容。
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:
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.