public static CustomerInfo Customer
{
get
{
if (System.Web.HttpContext.Current.Session["CustomerData"] == null)
{
System.Web.HttpContext.Current.Response.Redirect("~/Account/Login");
return new CustomerInfo();
}
else
{
return (CustomerInfo)System.Web.HttpContext.Current.Session["CustomerData"];
}
}
set
{
System.Web.HttpContext.Current.Session["CustomerData"] = value;
}
}
때마다 HttpContext.Current.Session["CustomerData"]
하는 대신 예외를주고 계정 컨트롤러에서보기를 로그인하는 리디렉션의, null
입니다.MVC5 라우팅 프로그래밍 C#을
프로퍼티 게터와로 리디렉션
을 사용할 수 있습니다 부작용은 나쁜 생각입니다. – Amy
세션을 확인하고 리디렉션하려면 [작업 필터] (https://www.codeproject.com/Articles/1095295/Check-Session-Timeout-by-Using-ActionFilters-in-MV)를 사용하십시오. –
Steve에게 액션 필터를 사용하라는 제안을 해주셨지만, getter에서 로그인보기로 리디렉션 할 수 있습니다. – Madhurima