无法身份MVC应用5注销 [英] Cannot logoff of identity MVC 5 application
本文介绍了无法身份MVC应用5注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个新的(空模板)ASP.NET MVC应用5,我不能这个应用程序注销。
我注销操作:
I'm making a new (empty template) ASP.NET MVC 5 application and I cannot logoff of this app. My logoff Action:
public ActionResult LogOff()
{
if (User.Identity.IsAuthenticated)
{
//break here
}
try
{
AuthenticationManager.SignOut();
if (User.Identity.IsAuthenticated || Request.IsAuthenticated)
{
//break here;
}
}
return RedirectToAction("Login", "Account");
}
启动类:
public partial class Startup
{
public void ConfigureAuth(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login")
});
app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
}
}
应用程序上下文:
Application Context:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", false)
{
}
}
连接字符串:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=.;Database=DataTest;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
动作注销等()执行没有问题,重定向我登录行动,但我仍然登录。
有什么错呢?
The action LogOff() executes without problems and redirects me to the 'Login' action but I am still logged in. What is wrong with it?
推荐答案
试试这个:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
//AuthenticationManager.SignOut();
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);
Session.Abandon();
return RedirectToAction("Login", "Account");
}
这篇关于无法身份MVC应用5注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文