asp.net-mvc – MVC 5具有身份验证模式的外部身份验证=表单
发布时间:2020-12-15 12:39:09 所属栏目: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 – Dropzone没有绑定到模型
- asp.net-mvc – 如何在asp.net mvc中处理分页?
- ASP.NET拒绝访问该路径
- asp.net-mvc – ASP.NET MVC忽略所有url结尾的“.html”
- asp.net-mvc – 在ajax请求中返回PDF
- asp.net – 如果我没有指定targetFramework =“4.0”会发生
- asp.net-mvc – ASP.NET MVC Beta 1:DefaultModelBinder错
- asp.net – 如何在Visual Studio中添加NUnit
- asp.net – 在WebForms中调试时关闭捆绑/缩小
- asp.net-mvc – 将List参数传递到ASP.NET MVC3中的自定义操
推荐文章
站长推荐
- asp.net-mvc – 什么时候使用ViewData而不是View
- asp.net – 如何MSDeploy构建的网站包到一个处女
- asp.net – 无法在UpdatePanel中下载文件
- asp.net-mvc – 使用ASP.NET MVC进行项目组织的最
- asp.net-mvc – Umbraco 7自定义cookie
- asp.net-mvc – ASP.NET MVC:在其中生成带有自定
- 勾选复选框时,禁用一些ASP.Net验证控件
- asp.net – Orchard CMS Media中的文件大小上传限
- asp.net-mvc – 为什么在ASP.NET MVC中使用lambd
- ASP.NET代码隐藏中的当前工作目录 – 我们可以依
热点阅读