[英]After Manager.SignInAsync - redirect to another page caused log out
I've added a login requirement to all pages except Index
. 我已为除
Index
之外的所有页面添加了登录要求。
services.AddMvc()
.AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizeFolder("/");
options.Conventions.AllowAnonymousToPage("/Index");
})
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
You can come to my index page with a username in Query
....?UserName=Whatever
您可以在
Query
....?UserName=Whatever
使用用户名进入我的索引页
I login the user by the username only. 我仅通过用户名登录用户。 After loggin successful, I redirect to another page, but the user name and password are required (although the login succeeded!).
登录成功后,我将重定向到另一个页面,但是需要用户名和密码(尽管登录成功!)。
The code at Index.cshtml: Index.cshtml上的代码:
@{
var user =
Manager.UserManager.FindByNameAsync(UserName).GetAwaiter().GetResult();
Manager.SignInAsync(user, true).GetAwaiter().GetResult();
if (Manager.IsSignedIn(user))
{
Response.Redirect(anotherPage, true);
}
}
You need to add app.UseAuthentication()
in startup Configure method: 您需要在启动Configure方法中添加
app.UseAuthentication()
:
app.UseAuthentication();
app.UseMvc(); // Order here is important.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.