asp.net-mvc – MVC 5具有身份验证模式的外部身份验证=表单
发布时间:2020-12-15 13:59:58 所属栏目: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); } } (编辑:4S站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – Visual Studio – 为什么.ASPX文件比.ASPX.CS文
- asp.net – 下载列表asp mvc
- ASP.NET:从C#代码隐藏显示警报
- asp.net-core – ASP.Net 5类库中的EntityFramework命令?
- .net – DNU发布 – 来自MSBuild的no-source
- asp.net-mvc – ASP.NET MVC查看引擎解析顺序
- ASP.NET MVC下Ajax.BeginForm方式无刷新提交表单实例
- asp.net-mvc – 如何在ASP.NET MVC中传递页面的元标记?
- 集成ASP.NET Webforms,WebAPI和AngularJS
- 模型 – 视图 – 控制器 – ASP.NET WebForms vs MVC [VS20
推荐文章
站长推荐
- asp.net-mvc-3 – ASP.Net MVC 3:在哪里处理会话
- asp.net-mvc – ASP.NET MVC获取具有特定配置文件
- 如何为ASP.NET身份设置密码规则?
- asp.net-mvc – ASP.NET MVC中的Windows Live ID
- asp.net-mvc – KendoUI网格显示总记录数
- ASP.NET异步方法问题
- asp.net-mvc – 存储库与DAL中的服务模式:EF和D
- 有没有办法加快asp.net中的编辑 – 编译 – 调试
- asp.net页面SqlCacheDependency缓存实例
- asp.net core标签助手的高级用法TagHelper+Form
热点阅读