asp.net-mvc – OWIN – Authentication.SignOut()不会删除cooki
我在Azure中有一个带有AD身份验证的MVC Web App.当我在本地运行网站时,使用Azure AD可以正常登录和退出.但我部署的Azure网站上的注销不起作用.用户仍然经过身份验证,因此SignOutCallback操作始终重定向到Home / Index.
这是我创建项目时创建的开箱即用的代码. public class AccountController : Controller { /// <summary> /// Use this method to sign into the website /// </summary> public void SignIn() { // Send an OpenID Connect sign-in request. if (!Request.IsAuthenticated) { HttpContext.GetOwinContext().Authentication.Challenge(new AuthenticationProperties { RedirectUri = "/" },OpenIdConnectAuthenticationDefaults.AuthenticationType); } } /// <summary> /// Use this method to sign out of the website /// </summary> public void SignOut() { string callbackUrl = Url.Action("SignOutCallback","Account",routeValues: null,protocol: Request.Url.Scheme); Request.GetOwinContext().Authentication.SignOut( new AuthenticationProperties { RedirectUri = callbackUrl },OpenIdConnectAuthenticationDefaults.AuthenticationType,CookieAuthenticationDefaults.AuthenticationType); } /// <summary> /// Use this method to redirect to Home page,once the request has been authenticated /// </summary> /// <returns>An <see cref="ActionResult"/> object.</returns> public ActionResult SignOutCallback() { if (Request.IsAuthenticated) { // Redirect to home page if the user is authenticated. return RedirectToAction("Index","Home"); } return View(); } } 我找到了一个有类似问题的here帖子,并尝试了它的建议,但它对我不起作用. 还有其他人遇到过这个问题吗? 解决方法
我弄清楚了问题是什么.我创建的带有AD身份验证的Azure中开箱即用的MVC Web App使用AspNet cookie.其中GetOwinContext().Authentication.SignOut清除.这对我来说在localhost上运行正常.当我将其部署到Azure然后在新的Azure门户中配置网站时,问题就出现了,以使用AD身份验证.它似乎将网站转换为Azure应用服务.现在cookie是AppServiceAuthSession cookie – 不再是AspNet cookie.因此,注销不再有效.
以下是我与之合作的Microsoft代表的回复: 我对此进行了更多研究,并与Azure AD团队和Azure网站团队进行了交流.显然,新的门户设置会为您处理所有auth组件.所以你真的有两种方法可以在你的网站上设置Auzre AD auth.您可以通过代码中看到的代码来实现它,您可以在其中访问AccountController的开箱即用的ASP.NET MVC项目. 或者另一种方法是让Azure通过在新的Azure门户中启用该设置来为您处理它.当您让新Azure门户执行此操作时,它会使用不同的会话cookie名称和不同的注销逻辑.似乎自动身份验证与编码的注销逻辑不兼容. 所以你的解决方法是正确的.您基本上有两个解决方法来启动和运行支持Azure AD身份验证的MVC应用程序: >通过代码创建支持AAD身份验证的MVC应用程序.手动将应用程序添加到该Azure AD租户应用程序列表以设置信任.通过MVC应用程序中的代码处理登录/注销 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net – html元素的命名约定
- asp.net – VB.NET – 如何使用Active Directory将SID转换为
- asp.net webforms jquery =无法按下按钮
- 如何在ASP.NET 4.0应用程序的IIS管理器中添加用户?
- 我是否完全误解了ASP.Net AJAX(更新面板)?
- asp.net – NullReferenceException在PipelineStepManager.
- .NET WebApi jsonapi.org支持
- asp.net-mvc – 如何在ASP.NET MVC中实现流畅的api?
- ASP.NET 2.0:如何将asp:Menu绑定到SqlDataSource?
- vs .net CS0006 C# 未能找到元数据文件 .dll
- ASP.NET中的Application和Cache有什么区别?
- asp.net-mvc – 如何判断我在ASP.NET MVC应用程序
- 如何在ASP.Net 4 Razor和Twitter Bootstrap中使用
- 实体框架 – 我们如何使用Breeze的本地时区生存
- asp.net – ReportViewer超时,尽管超时设置
- asp.net-mvc – 神控制器 – 如何防止它们?
- asp.net-mvc – MVC – 如何在整个应用程序中实例
- asp.net-mvc – 我可以在这里使用路由约束吗?
- asp.net-mvc – 如何在ASP.NET MVC中执行[Requir
- asp.net – SignalR/signalr/hubs 404未找到