简体   繁体   English

如何从具有 AAD 设置的 asp.net mvc 应用程序调用外部网站

[英]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.

相关问题 如何从ASP.NET MVC解决方案调用外部URL - How to call an external URL from a ASP.NET MVC solution 如何防止某些在ASP.Net MVC中具有某些特殊字符的URL执行 - How to prevent some url from execute which has some special charcters in ASP.Net MVC 调用随机超时的外部服务会杀死ASP.NET MVC应用程序 - Calling external services which randomly timeout kills the ASP.NET MVC application 如何结合两个asp.net mvc网站 - How to combine two asp.net mvc websites 如何从控制台应用程序在 ASP.NET MVC 应用程序中进行身份验证 - How to authenticate in an ASP.NET MVC application from a console application 在 ASP.NET MVC 方法中创建一个应用程序,该方法具有以下功能: - Create an application in ASP.NET MVC approach which has the following functionalities: 如何使用会话和类asp.net mvc 6进行调用 - How to use session and call from class asp.net mvc 6 如何从ActionLink asp.net Mvc 3调用jquery函数? - How to call jquery function from ActionLink asp.net Mvc 3? 如何从asp.net MVC 4中的按钮单击调用控制器 - How to call controller from the button click in asp.net MVC 4 在asp.net MVC控制器中调用异步外部Web服务 - Call asynchronous external web service in asp.net MVC controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM