【问题标题】:Azure Web App redirects to localhost URL when testing on web; redirects to web URL when testing locallyAzure Web App 在 Web 上进行测试时重定向到 localhost URL;在本地测试时重定向到 Web URL
【发布时间】:2018-08-11 09:06:25
【问题描述】:

我正在尝试在我的 Azure Web 应用程序的本地测试和云测试之间进行无缝移动。以下是我的 Web.Config 文件中的一个 sn-p。

<appSettings>
    <add key="ida:ClientId" value="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" />
    ... more items ...
</appSettings>

ClientId 的值对应于我的 Azure Active Directory 实例中的“应用注册”对象的值。当我单击该对象并导航到设置 --> 回复 URL 时,条目为 https://localhost:xxxxx/

我的问题是:当我将 Azure Web App 发布到云时,我被重定向到上面的 localhost URL。但是,如果我添加另一个回复 URL 条目https://mywebappname.mydomain.com,那么当我尝试在本地进行测试时,我会被重定向到 Web URL 而不是 localhost URL。

我想要一种本地和云端无缝测试的方法:在本地和云端测试时,我希望被重定向到正确的 URL。为了实现这一点,我缺少哪些配置?

---- 更新----

此外,当我在 Visual Studio 2017 中右键单击 Web 应用程序项目,然后单击属性时,我会进入此屏幕。这是我设置的一些附加属性,它们重定向到https://localhost:xxxxx/。我需要改变这个吗?如果是这样,我怎样才能在项目的属性中同时拥有两个重定向 URL?

【问题讨论】:

  • 问题是您的应用没有指定重定向 URL。所以 AAD 随机选择一个。您必须配置身份验证部分,以便它们指定 redirect_uri
  • @juunas,你能详细说明一下吗?我在应用程序的哪个位置指定重定向 URL - 也许是 Web.config?我是否必须在应用程序中指定多个重定向 URL?如果是这样,应用程序如何知道选择哪一个?
  • @StephenMuecke 感谢您提供有关变换的文章。但是,我注意到这篇文章的日期是 2011 年 5 月,那是很久以前的事了。是否有更新的方法来完成这项任务,或者这是最新的方法?
  • @juunas 我还添加了一个包含屏幕截图的更新,以帮助您查看项目的更多配置。非常感谢!

标签: asp.net-mvc azure azure-web-app-service azure-active-directory


【解决方案1】:

我最终通过使用 Web.config 转换语法解决了这个问题(请参阅原帖 cmets 中 Stephen Muecke 的链接)。

在与Web.config 相同的目录下,我添加了一个Web.Release.config。现在,如果在 Visual Studio 中选择“Release”构建,那么Web.Release.config 转换配置文件将用于将Web.config 文件的“ida:RedirectUri”键替换为转换配置文件中的值。

这里是Web.Release.config

<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <appSettings>
    <add key="ida:RedirectUri" value="https://<mywebappname>.<mywebappdomain>.com/" xdt:Transform="Replace" />
  </appSettings>
</configuration>

这里是来自非常大的Web.config的sn-p

<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit https://go.microsoft.com/fwlink/?LinkId=301874 -->
...
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  ...
  <appSettings>
    <add key="ida:RedirectUri" value="https://localhost:xxxxx/" xdt:Transform="Replace" />
    ...
  </appSettings>
  ...
</configuration>

这样,默认重定向到localhost

【讨论】:

  • 当我尝试运行它时,我收到一个错误,提示无法识别属性'xmlns:xdt'。请注意,属性名称区分大小写
猜你喜欢
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 2015-02-04
  • 1970-01-01
  • 2016-01-27
  • 1970-01-01
  • 2012-12-02
  • 2013-10-19
相关资源
最近更新 更多