2012-07-13 7 views
0

ActionFilterAttribute에서 Session_Start 호출과 OnActionExecuting 간의 Session은 어떻게됩니까?ASP.NET MVC에서 세션이 지워짐

protected void Session_Start(object sender, EventArgs e) 
{ 
    Session["GoToBuyPage"] = true; 
} 

과 ActionFilterAttribute에서 여기에 액세스하려고 :

public override void OnActionExecuting(ActionExecutingContext filterContext) 
{ 
    bool goToPage = (bool)Session["GoToBuyPage"]; 

을 항상 null의 나는 이런 식으로 뭔가를 설정 몇 가지 이유를 들어

. 어떤 아이디어?

답변

0

ActionFilterAttributeSession 속성이 없습니다. 따라서 코드가 어떻게 컴파일되는지조차 알지 못합니다. 나를 위해 완벽하게 정상적으로 다음 작품 :

액션 필터 :

public class FooAttribute: ActionFilterAttribute 
{ 
    public override void OnActionExecuting(ActionExecutingContext filterContext) 
    { 
     bool goToPage = (bool)filterContext.HttpContext.Session["GoToBuyPage"]; 
     filterContext.Result = new ContentResult 
     { 
      Content = goToPage.ToString() 
     }; 
    } 
} 

컨트롤러 :

public class HomeController : Controller 
{ 
    [Foo] 
    public ActionResult Index() 
    { 
     return View(); 
    } 
} 

Session_Start :

protected void Session_Start(object sender, EventArgs e) 
{ 
    Session["GoToBuyPage"] = true; 
}