asp.net-mvc – MVC 5具有身份验证模式的外部身份验证=表单
发布时间:2020-12-15 14:41:47 所属栏目:asp.Net 来源:互联网
导读:我正在关注 this tutorial以创建一个带有外部身份验证的简单MVC 5应用程序.它工作正常,但是,如果我将身份验证模式=“无”更改为身份验证模式=“表单”,它将停止工作. 我搞砸了: await HttpContext.GetOwinContext().Authentication.GetExternalLoginInfoAsyn
我正在关注 this tutorial以创建一个带有外部身份验证的简单MVC 5应用程序.它工作正常,但是,如果我将身份验证模式=“无”更改为身份验证模式=“表单”,它将停止工作. 我搞砸了: await HttpContext.GetOwinContext().Authentication.GetExternalLoginInfoAsync() 我正在阅读很多关于在重定向上禁止FormsAuthentication的内容.我不知道这是不是正确的道路,但我试图安装这个nuget packet,问题仍然存在. 那么,为什么每次更改身份验证模式时我都会变为空? 解决方法通过将Response.SuppressFormsAuthenticationRedirect = true添加到ChallengeResult类,我能够使这个工作(OWIN和FormsAuthentication).如果您正在学习本教程,请参阅以下代码: public class ChallengeResult : HttpUnauthorizedResult { public ChallengeResult(string provider,string redirectUri) : this(provider,redirectUri,null) { } public ChallengeResult(string provider,string redirectUri,string userId) { LoginProvider = provider; RedirectUri = redirectUri; UserId = userId; } public string LoginProvider { get; set; } public string RedirectUri { get; set; } public string UserId { get; set; } public override void ExecuteResult(ControllerContext context) { // this line did the trick context.RequestContext.HttpContext.Response.SuppressFormsAuthenticationRedirect = true; var properties = new AuthenticationProperties() { RedirectUri = RedirectUri }; if (UserId != null) { properties.Dictionary[XsrfKey] = UserId; } context.HttpContext.GetOwinContext().Authentication.Challenge(properties,LoginProvider); } } (编辑:哈尔滨站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net Xml绑定到数据控件的具体实现
- ASP.NET成员:拒绝用户阻止CSS,页面无法正确呈现?
- asp.net – Umbraco CMS(.NET):加载xslt /用户控件的日志错
- asp.net-mvc – 如何使用带有IEnumerable的Html.CheckBox(l
- asp.net-mvc – 删除布局将默认为_ViewStart,为什么找不到部
- asp.net-mvc – ASP.NET MVC jQueryUI datepicker在使用AJA
- asp.net中Session缓存与Cache缓存的区别分析
- asp.net – 手动更新表单认证券:
- 何时在ASP.NET上选择LAMP?
- asp.net – 获得“System.Web.Mvc.Html.MvcForm”一页
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC现在是“开源”.这是
- asp.net – 在客户端启用/禁用RequiredValidator
- asp.net jquery+ajax异步刷新实现示例
- asp.net-mvc – ASP.NET Web Api – 将对象发布到
- 是否可以使用ASP.NET ScriptManager来使用Window
- asp.net – 共享.NET应用程序池
- asp.net – 我可以在超链接上显式指定NavigateUr
- asp.net-mvc – 无法在Web服务器上启动调试. Web
- asp.net webservice返回json的方法
- LoginView中的ASP.NET LoginStatus不会触发Loggi
热点阅读