我试图重定向到一个不同的登录URL在ASP.NET MVC6ASP.NET核心,更改默认重定向未经授权
我的帐户控制器登录方法有Route
属性来更改URL。
[HttpGet]
[AllowAnonymous]
[Route("login")]
public IActionResult Login(string returnUrl = null)
{
this.ViewData["ReturnUrl"] = returnUrl;
return this.View();
}
当试图访问unathorized页,我重定向到无效的URL,它应该只是
/login
而是我得到http://localhost/Account/Login?ReturnUrl=%2Fhome%2Findex
我已经配置了cookie认证路径如下:
services.Configure<CookieAuthenticationOptions>(opt =>
{
opt.LoginPath = new PathString("/login");
});
我hav e添加了默认过滤器,以确保所有网址默认情况下都需要身份验证。
services.AddMvc(
options =>
{
options.Filters.Add(new AuthorizeFilter(new AuthorizationPolicyBuilder().RequireAuthenticatedUser().Build()));
});
我已检查该URL /login
其实不加载登录页面,而/account/login
并不如预期。
编辑:我已经离开了路线为是,(除了改变默认的控制器和行动)
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Site}/{action=Site}/{id?}");
});
你可以在'Configure()'中显示你的路由配置吗? – juunas
@juunas:我已经添加了路线到问题 – Jim
你使用的是asp.net-core-identity? – tmg