Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net core 使用asp.net core重定向到超时页面_Asp.net Core - Fatal编程技术网

Asp.net core 使用asp.net core重定向到超时页面

Asp.net core 使用asp.net core重定向到超时页面,asp.net-core,Asp.net Core,配置超时页面的正确方法是什么?当会话过期并访问授权页面时,该页面会自动重定向到超时页面 我将我的会话超时设置为: services.AddSession(options => { options.IdleTimeout = TimeSpan.FromMinutes(120); }); 配置cookie名称: services.AddSession(options => { options.CookieName = ".MyProjectName.Session";

配置超时页面的正确方法是什么?当会话过期并访问授权页面时,该页面会自动重定向到超时页面

我将我的会话超时设置为:

services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromMinutes(120);
});
配置cookie名称:

services.AddSession(options =>
{
  options.CookieName = ".MyProjectName.Session";
  options.IdleTimeout = TimeSpan.FromMinutes(120);
});
并尝试使用以下属性:

[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class CheckSessionOutAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext context = HttpContext.Current;
        if (context.Session != null)
        {
            if (context.Session.IsNewSession)
            {
                string sessionCookie = context.Request.Headers["Cookie"];

                if ((sessionCookie != null) && (sessionCookie.IndexOf("MyProjectName.Session") >= 0))
                {
                    FormsAuthentication.SignOut();
                    string redirectTo = "~/Account/Login"; //YOUR LOGIN PAGE HERE
                    if (!string.IsNullOrEmpty(context.Request.RawUrl))
                    {
                        redirectTo = string.Format("~/Account/Login?ReturnUrl={0}", HttpUtility.UrlEncode(context.Request.RawUrl));
                        filterContext.Result = new RedirectResult(redirectTo);
                        return;
                    }

                }
            }
        }

        base.OnActionExecuting(filterContext);
    }
}
用法:

[CheckSessionOut]
public ViewResult Index()
{
}
配置cookie名称:

services.AddSession(options =>
{
  options.CookieName = ".MyProjectName.Session";
  options.IdleTimeout = TimeSpan.FromMinutes(120);
});
并尝试使用以下属性:

[AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
public class CheckSessionOutAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        HttpContext context = HttpContext.Current;
        if (context.Session != null)
        {
            if (context.Session.IsNewSession)
            {
                string sessionCookie = context.Request.Headers["Cookie"];

                if ((sessionCookie != null) && (sessionCookie.IndexOf("MyProjectName.Session") >= 0))
                {
                    FormsAuthentication.SignOut();
                    string redirectTo = "~/Account/Login"; //YOUR LOGIN PAGE HERE
                    if (!string.IsNullOrEmpty(context.Request.RawUrl))
                    {
                        redirectTo = string.Format("~/Account/Login?ReturnUrl={0}", HttpUtility.UrlEncode(context.Request.RawUrl));
                        filterContext.Result = new RedirectResult(redirectTo);
                        return;
                    }

                }
            }
        }

        base.OnActionExecuting(filterContext);
    }
}
用法:

[CheckSessionOut]
public ViewResult Index()
{
}

你好@Dawid,这是为asp.net核心设计的?你好@Dawid,这是为asp.net核心设计的?