我有一个标准的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>
有谁能建议我做错了什么?它现在导致了重大问题。
干杯!
答案 0 :(得分:4)
检查项目中int v = cbrt(n);
printf("%d\n", v);
文件夹中是否有Startup.Auth.cs
个文件。
App_Start
并从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
根据您使用的asp.net版本和身份,您应该看看这个
ASP.NET Identity AuthenticationManager vs. SignInManager and cookie expiration
答案 1 :(得分:0)
对我来说,这是web.config,注释后面的行
<system.webServer>
<modules>
<!--<remove name="FormsAuthentication" />
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
-->
</modules>
</system.webServer>