ASP.NET Core中身份验证

ywxt       5 年, 3 月 前       2234

如果没有登录,那么加了验证之后会跳到登录页面。

我想知道他是怎么知道该往哪儿跳转?难道登陆页面的路径必须是固定的/Account/Login ??

4 回复  |  直到 Dec 20, 2018

yufei

#1   •   5 年, 3 月 前   •  

这个主要是通过 CookieAuthenticationOptions 类来配置的,类的介绍路径为 https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.cookies.cookieauthenticationoptions?view=aspnetcore-2.1

如果你要改变这个地址,可以参考 https://github.com/aspnet/Identity/issues/539 这里的解决方案

services.ConfigureApplicationCookie(options =>
{
    options.AccessDeniedPath = "/Identity/Account/AccessDenied";
    options.Cookie.Name = "YourAppCookieName";
    options.Cookie.HttpOnly = true;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
    options.LoginPath = "/Identity/Account/Login";
    // ReturnUrlParameter requires 
    //using Microsoft.AspNetCore.Authentication.Cookies;
    options.ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
    options.SlidingExpiration = true;
});

yufei

#2   •   5 年, 3 月 前   •  

我去,评论的 markdown 支持怎么没有了....

yufei

#3   •   5 年, 3 月 前   •  

回复终于支持 markdown 了。http://www.twle.cn/

ywxt

#4   •   5 年, 3 月 前   •  

感谢!!

简单教程 = 简单教程,简单编程
简单教程 是一个关于技术和学习的地方
现在注册
已注册用户请 登入
什么意思
什么意思
关于   |   FAQ   |   我们的愿景   |   广告投放   |  博客

  简单教程,简单编程 - IT 入门首选站

Copyright © 2013-2022 简单教程 twle.cn All Rights Reserved.