asp.net-mvc – MVC 5具有身份验证模式的外部身份验证=表单
发布时间:2020-12-15 14:52:59 所属栏目: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-mvc – ASP.net MVC:在RenderAction中获
- asp.net全局资源错误’找不到具有键”的资源对象’
- asp.net-mvc – 使用IIS7.5将网站中的URL绑定到另一个网站控
- asp.net – web部署工具2.1和web部署3.5有什么区别?哪一个
- asp.net – 当绑定值包含冒号时,如何绑定GridView HyperLin
- WPAD查询从ASP.NET调用webservice
- asp.net 根据汉字的拼音首字母搜索数据库(附 LINQ 调用方法
- 如何在ASP.NET自定义控件中持久保存List属性?
- Jquery 组合form元素为json格式,asp.net反序列化
- asp.net-web-api – 在WebApi OData中为OData服务文档基URL
推荐文章
站长推荐
- 各大输入法分类词库内部格式的简单比较
- asp.net文件上传解决方案(图片上传、单文件上传
- .net – 加密ApplicationServices ConnectionStr
- asp.net – 来自WebHttpBinding的WCF服务中的Acc
- 解决asp.net Sharepoint无法连接发布自定义字符串
- asp.net-mvc – 使用Entity FrameWork保存更改/更
- asp.net-mvc – ASP.NET MVC推荐的依赖注入框架是
- ASP.NET身份和移动客户端
- ASP.NET 2.0和4.0似乎在Forms身份验证中以不同方
- asp.net-mvc – 带有lambda表达式的ASP.net MVC
热点阅读