- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个标准的 MVC 项目,其中包含 UserManager 和 SignInManager 对象以及 AccountController,以及预先创建的登录和注册类型功能。
我可以向我的 AspNetUsers 表注册新用户,但是当我登录时,我会调用:-
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
数据正确地从表单中传递出来,结果是成功,这正是我所期望的。
然后我尝试了以下重定向:-
case SignInStatus.Success:
//return RedirectToLocal("/admin/");
return RedirectToAction("Index", "Admin");
但在任何页面上,登录成功后,User.Identity.IsAuthenticated 始终为 false,而 User.Identity.Name 为空字符串。
我做错了什么?我过去以相同的方式和相同的设置完成了另一个项目,并且我遇到了零问题。
web.config
<system.web>
<compilation debug="true" targetFramework="4.5.1" />
<httpRuntime targetFramework="4.5.1" />
<!--<authentication mode="Forms">
<forms loginUrl="~/Account/Login/" timeout="1000" />
</authentication>-->
<authentication mode="None" />
</system.web>
<modules>
<remove name="FormsAuthentication" />
</modules>
任何人都可以建议我做错了什么吗?它现在引起了重大问题。
干杯!
最佳答案
检查项目的 App_Start
文件夹中是否有 Startup.Auth.cs
文件。
public partial class Startup {
public void ConfigureAuth(IAppBuilder app) {
// This uses cookie to store information for the signed in user
var authOptions = new CookieAuthenticationOptions {
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
LogoutPath = new PathString("/Account/Logout"),
ExpireTimeSpan = TimeSpan.FromDays(7),
};
app.UseCookieAuthentication(authOptions);
}
}
并从 Startup
类调用
public partial class Startup {
public void Configuration(IAppBuilder app) {
// Surface Identity provider
ConfigureAuth(app);
//..other start up code
}
}
根据您使用的 asp.net 版本和身份,您应该查看此内容
ASP.NET Identity AuthenticationManager vs. SignInManager and cookie expiration
关于asp.net-mvc - PasswordSignInAsync 成功后 User.Identity.IsAuthenticated 始终为 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36366059/
你好,我正在编写一个 MVC 应用程序,它只能允许用户使用三个参数登录,即 ID、电子邮件和密码。我的问题是 PasswordSignInAsync 有两个主要参数电子邮件和密码。我如何覆盖它以允许
AccountController.cs 包含 AccountController 类。该类的 Login 方法失败。具体来说, var result = await SignInManager.Pa
所以,方法SignInManager.PasswordSignInAsync有一个最后的参数 lockoutOnFailure 当为真时,如果用户输入错误的凭据则将其锁定。但是已经有一个名为 MaxF
在我的应用程序中,我使用 ASP.NET Identity。一切都工作正常,但通过测试,我发现以下命令会产生许多数据库访问:SignInManager.PasswordSignInAsync: var
我有一个运行 .Net 4.5.1 和 Identity 2 的 Web 应用程序。 在我的 WebApi 中,我有一个 iOSLoginController.cs,它使用从主 .NET Identi
我正在使用Identity 3.0创建Web应用程序,并且SignInManager PasswordSignInAsync()方法有问题。我就像在文档中一样使用它,但是它不返回任何内容(应用程序代码
将我的应用程序从 .NET Framework 4.6 转换为 .NET Core 2 后,我对数据库进行了请求的更改以支持新的身份模型,即添加到 AspNetUsers 和新表的几个字段。 记录在
我一直在使用此代码登录: // // GET: /Account/Login [AllowAnonymous] public ActionResult Login(string returnUrl)
使用 asp net core 身份 - 当用户提供密码和用户名以获取 jwt token 时,他们将凭据发布到/api/token 我的 token Controller 方法应该使用 userma
我正在尝试在我们的应用程序上设置双因素身份验证。更新 AspNetUsers 表中的用户并将其 TwoFactorEnabled 值设置为 1 以进行测试。 调试时,signInManager.Pas
我已经使用 Microsoft 提议的方式向 AspNetUsers 添加了一个新列: public class ApplicationUser : IdentityUser { public
这是我的登录方法: [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task Login(LoginViewMo
.Net Core 1.0.0 - SDK Preview 2 (x64) .Net Core 1.0.0 - VS "15" Preview 2 (x64) .Net Core 1.0.0 - Ru
问题涉及 ASP.NET Core 2.0 中的身份验证。 PasswordSignInAsync() 之后,result 的状态为成功。所以我将重定向到 StaticController 中的操作
我目前正在实现登录我的 ASP.NET MVC 项目的功能。我正在尝试尽可能多地使用提供的方法。 目前,我在我的数据库中建立了一个名为 User 的表,其中存储了所有用户名、密码和其他有关用户的详细信
我有一个标准的 MVC 项目,其中包含 UserManager 和 SignInManager 对象以及 AccountController,以及预先创建的登录和注册类型功能。 我可以向我的 AspN
我是 ASP.Net Core 的新手,正在尝试创建用户身份验证系统。我正在使用 ASP.Net Core Identity 用户管理。我有以下用于登录用户的代码。 /Areas/Identity/P
我正在编写用于外部应用程序的代码。我正在尝试使用 Microsoft Identity 2.0 和 ASP.NET MVC 5。我已经自定义了 UserViewModel 以保存 FirstName
构建自定义 IUserPasswordStore 以连接到旧系统的用户名/密码表。密码使用表中的自定义代码进行哈希处理,因此我需要为 PasswordSignInAsync 编写自定义代码。 我是否需
我正在关注有关 IdentityUser 的一些教程,我认为我的做法与教程中的完全一样,但是当我尝试登录时,即使 _signInManager 成功,我也会收到“MyIdentity: False”(
我是一名优秀的程序员,十分优秀!