asp.net-mvc – MVC 5具有身份验证模式的外部身份验证=表单
发布时间:2020-05-22 21:50:14 所属栏目: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-3 – 在控制器动作中使用T4MVC生成URL
- asp.net – IIS URL重写:强制规范主机名和HTTP到HTTPS重定
- ASP.NET线程敏捷 – 如何克服?
- asp.net – 我可以在超链接上显式指定NavigateUrl吗?
- 我们可以将asp.net mvc 4应用程序部署到带有Windows容器的d
- asp.net-mvc-3 – ASP.NET MVC 3认证/授权
- 为什么我要在公共站点上使用ASP.NET MVC,在Intranet上使用W
- asp.net-mvc – 在ASP.NET MVC中动态更改主模板
- asp.net-core – 什么应该是WEB API Action Method的返回类
- asp.net-mvc – ASP.NET MVC – Elmah不工作,返回404页面为
推荐文章
站长推荐
- 身份验证 – 如何为Asp.NET MVC 5创建ClaimsIden
- asp.net-mvc-4 – 如何在asp.net MVC4查看页面中
- asp.net-mvc-3 – 实体框架,MVC 3,LINQ To Entit
- asp.net – 如何在Web / Windows窗体中将IronRub
- asp.net – 没有参数的WebResource.axd请求 – 这
- asp.net – 如何在回发中保存asp:HiddenField值
- asp.net – 如何创建Generic StateManagedCollec
- asp.net-mvc – TempData keep()vs peek()
- asp.net-mvc – ASP.NET MVC的生产力?
- global-variables – MVC 3 Razor _ViewStart中的
热点阅读
