asp.net-mvc - 在 Web 上测试时,Azure Web App 重定向到本地主机 URL;本地测试时重定向到 Web URL

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

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

<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 发布到云时,我被重定向到上述本地主机 URL。但是,如果我添加另一个回复 URL 条目 https://mywebappname.mydomain.com ,然后当我尝试在本地测试时,我会被重定向到 Web URL 而不是本地主机 URL。

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

---- 更新 ----

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

Web App Properties

最佳答案

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

在与 Web.config 相同的目录中,我添加了 Web.Release.config。现在,如果在 Visual Studio 中选择“发布”构建,则 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

的片段
<?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

关于asp.net-mvc - 在 Web 上测试时,Azure Web App 重定向到本地主机 URL;本地测试时重定向到 Web URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49081172/

相关文章:

asp.net-mvc - 如何使用 MVC Controller.User 属性引用我自己的表?

c# - 连接oracle的odbc指令

azure - Azure 容器服务和容器 Web 应用程序之间的区别

azure - 使用发件人和收件人的公司电子邮件地址通过我公司 Azure 订阅的 Azure Functions 发送电子邮件

html - MVC : Not render css class for certain view?

Azure 网站和 VM 位于同一数据中心

azure - 创建 Azure 网站部署槽 - REST API 示例

azure - Terraform 将 SSL 证书绑定(bind)到 Azure WebApp

azure - 使用部署槽为每个环境的 React App 提供不同的 API URL

c# - 返回的json中的双引号