【问题标题】:Error when deploying an mvc2 application in an IIS在 IIS 中部署 mvc2 应用程序时出错
【发布时间】:2011-01-28 19:13:25
【问题描述】:

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

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

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

这是错误:

// 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        }

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

【问题讨论】:

  • 请复制/粘贴 asp.net 错误信息。
  • 我已经发布了错误的跟踪和一些代码......
  • 在第 151 行放置一个断点。查看“modelo”对象和“DatosIdentificacion”属性。我相信你会发现这两个中的一个是空的。
  • 这就是问题所在……在开发和测试环境下,我们能够看到堆栈跟踪并进行调试。这些环境运行良好。问题出现在生产环境中,我们无法在那里调试。我们怀疑它必须与 IIS 上的会话管理有关...

标签: .net asp.net-mvc-2 iis web-applications deployment


【解决方案1】:

从您提供的信息中很难说为什么您的模型在 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
    ...
}

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

【讨论】:

  • 这就是问题所在……在开发和测试环境下,我们能够看到堆栈跟踪并进行调试。这些环境运行良好。问题出现在生产环境中,我们无法在那里调试。我们怀疑它必须与 IIS 上的会话管理有关...
  • @JPCF,我建议您使用您选择的日志框架来跟踪异常详细信息。你不是在使用日志框架吗?你不是在跟踪生产中的错误吗?你应该。 log4net 是日志框架的流行选择,它允许您跟踪各种来源,包括文本文件、XML 文件、SQL 数据库……如果您不想使用第三方日志框架,您可以很好地使用内置-in .NET 框架本身的跟踪工具。
  • 记录器显示相同的消息。我们正在使用 Windows 事件查看器。
猜你喜欢
  • 1970-01-01
  • 2018-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多