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にアクションフィルタを使用するよう提案しましたが、ゲッターからログインビューにリダイレクトすることは可能です。 – Madhurima