在ASP.NET MVC 3 Controller生命周期中是否构建了ControllerContext?
我在控制器的构造函数中有以下代码:
if ((Session == null || Session.IsNewSession || Session["SecureAuthHash"] == null) &&
(ValueProvider == null || ValueProvider.GetValue("controller").ToString() != "Account"))
{
RedirectToAction("Login", "Account");
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: controllerContext
Run Code Online (Sandbox Code Playgroud)
什么时候controllerContext可用,所以我的代码可以运行?这应该在任何其他代码之前运行,所以我真的不想把它放在每个动作方法中......但我想这可能是唯一的方法.
TIA,Benjy
在ASP.NET MVC 3 Controller生命周期中是否构建了ControllerContext?
这发生在Initialize方法内部.永远不要访问控制器构造函数中的任何HttpContext绑定对象.