【发布时间】:2016-04-08 06:03:55
【问题描述】:
我使用最新版本的 ASP.NET MVC 6。
以下设置设置Startup.cs文件:
public void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Cookies.ApplicationCookie.LoginPath = new PathString("/account/login");
options.Cookies.ApplicationCookie.AccessDeniedPath = new PathString("/error/accessdenied");
options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromDays(1);
options.Cookies.ApplicationCookie.SlidingExpiration = false;
options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
options.Cookies.ApplicationCookie.AutomaticChallenge = true;
})
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
}
在Account控制器中有动作Login
[HttpGet]
[AllowAnonymous]
public IActionResult Login(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}
在上面的方法中我得到returnUrl没有问题。
同样在控制器Error有动作AccessDenied
[AllowAnonymous]
[HttpGet]
public IActionResult AccessDenied(string returnUrl = null)
{
ViewData["ReturnUrl"] = returnUrl;
return View();
}
但是当用户没有权限访问该站点的页面时,系统会将用户转发到一个页面../error/accessdenied。
目前,在我被重定向后returnUrl 值是null。
我可以获取用户被重定向的页面地址(以及它适用于LoginPath)吗?
【问题讨论】:
标签: c# asp.net-mvc asp.net-core asp.net-core-mvc asp.net-core-1.0