[英]How to call external websites from a asp.net mvc application which has AAD setup
I have followed the documentation at https://docs.microsoft.com/en-gb/azure/active-directory/develop/tutorial-v2-asp-webapp and successfully created the web application and deployed to Azure.我已按照https://docs.microsoft.com/en-gb/azure/active-directory/develop/tutorial-v2-asp-webapp上的文档并成功创建了 web 应用程序并部署到 Z3A580F3B1422038673FF8 My application needs to get IP and geolocation of the logged-in user.我的应用程序需要获取 IP 和登录用户的地理位置。 I am using https://ip-api.io/json/ and http://checkip.dyndns.org/ to get these information.我正在使用https://ip-api.io/json/和http://checkip.dyndns.org/来获取这些信息。 I am doing webclient calls to fetch the data:我正在做 webclient 调用来获取数据:
WebClient client = new WebClient();
string jsonstring = client.DownloadString(url);
return jsonstring;
This is working when I run the code using IE but fails when using Chrome, Firefox and IE in Private browsing.这在我使用 IE 运行代码时有效,但在私人浏览中使用 Chrome、Firefox 和 IE 时失败。 I get the Microsoft screen to enter my email address and password but then get the error message "We couldn't sign you in. Please try again."我在 Microsoft 屏幕上输入我的 email 地址和密码,但随后收到错误消息“我们无法让您登录。请重试。” If I comment the code which is calling these external links, I am able to login.如果我评论调用这些外部链接的代码,我就可以登录。
I am not sure what is causing this behaviour and any help will be greatly appreciated.我不确定是什么导致了这种行为,任何帮助将不胜感激。
Thanks谢谢
I found the solution by making use of optional claims: "idToken": [ { "name": "ipaddr", "essential": false, "additionalProperties": []我通过使用可选声明找到了解决方案: "idToken": [ { "name": "ipaddr", "essential": false, "additionalProperties": []
} ] }]
This should be added in the app's manifest on Azure.这应该添加到 Azure 上的应用程序清单中。
More details at https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-optional-claims更多详细信息请参见 https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-optional-claims
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.