Error when deploying an mvc2 application in an IIS
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\calvare开发者_如何学Cz\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?
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.
精彩评论