asp.net-mvc – 使用C#以编程方式将AzureAd / OpenId验证为MVC控
发布时间:2020-12-16 09:20:05 所属栏目:asp.Net 来源:网络整理
导读:我已经覆盖了内置的WebClient,如下所示.然后我打电话给它 public class HttpWebClient : WebClient{ private Uri _responseUri; public Uri ResponseUri { get { return _responseUri; } } protected override WebResponse GetWebResponse(WebRequest reques
我已经覆盖了内置的WebClient,如下所示.然后我打电话给它
public class HttpWebClient : WebClient { private Uri _responseUri; public Uri ResponseUri { get { return _responseUri; } } protected override WebResponse GetWebResponse(WebRequest request) { WebResponse response = base.GetWebResponse(request); _responseUri = response.ResponseUri; return response; } } 然后我像这样消耗它: using (HttpWebClient client = new HttpWebClient()) { client.Headers[HttpRequestHeader.Authorization] = $"Bearer { _token }"; client.Headers[HttpRequestHeader.ContentType] = "application/json"; client.UploadData(_url,Encoding.UTF8.GetBytes(_data)); string queryString = client.ResponseUri.Query.Split('=').Last(); } 响应uri返回“https://login.microsoftonline”,而不是使用查询字符串从MVC控制器返回的url,因为它首先使用AzureAd / OpenId使用该承载令牌进行身份验证.如果我调用它两次,则返回原始的_url而不是重定向的_url.如果我删除AzureAd身份验证它工作正常.有没有办法强制响应uri回来,因为MVC控制器设置它? 解决方法
假设您使用’USEOpenIdConnectAuthentication’并将其配置为使用AAD身份验证,您可以通过设置Notifications.RedirectToIdentityProvider来修改重定向uri,例如:
Notifications = new OpenIdConnectAuthenticationNotifications { RedirectToIdentityProvider = async _ => { _.ProtocolMessage.RedirectUri = _.Request.Uri.ToString(); } } 如果你使用别的东西,或者我不明白你的问题 – 请提供更多信息 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET MVC – 开始的原因
- asp.net-mvc – 如何在ASP.NET MVC视图中访问路由参数?
- asp.net-mvc – 调试流畅的验证规则
- asp.net core html 选择框checked选中
- asp.net – 从Web应用程序打印
- asp.net-mvc – NHaml是否具有content_for布局能力?
- asp.net-mvc-2 – Plus()在MVC中的参数引起404在IIS 7.0
- 在ASP.NET中,如何让浏览器将字符串内容下载到文件中? (C#)
- asp.net – 插入多行的最佳方式(ADO.NET)
- asp.net-mvc – 在MVC 5中创建一个新视图,在HTTP 404中打开