在IIS/Azure中的ASP.NET Core的URL中允许冒号(:) [英] Allow colon (:) in URL for ASP.NET Core in IIS/Azure

查看:97
本文介绍了在IIS/Azure中的ASP.NET Core的URL中允许冒号(:)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要部署到Azure的ASP.NET Core应用程序,该应用程序在URL中输入一个包含冒号(时间戳)的字符串.

I've got an ASP.NET Core app that I'm deploying to Azure that takes in a string in the URL that contains colon (a time stamp).

例如:http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07:03:43+00:00http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07%3a03%3a43%2B00%3a00 URL编码.

For example: http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07:03:43+00:00, or http://localhost:5000/Servers/208.100.45.135/28000/2017-03-15T07%3a03%3a43%2B00%3a00 URL-encoded.

当使用Kestrel(dotnet run)在本地运行时,此方法工作得很好,但是在部署到Azure之后,我收到此错误:The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

This works perfectly fine when running locally using Kestrel (dotnet run), but after deploying to Azure I receive this error: The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

快速搜索表明,这是由于URL中使用了无效字符(即冒号)造成的.传统的修复方法是将此部分添加到web.config:

A quick search reveals that it's due to invalid characters being used in the URL, namely the colon. The traditional fix is to add this section to web.config:

 <system.web>
     <httpRuntime requestPathInvalidCharacters="" />
 </system.web>

但是,将其添加到Azure上的web.config后,我发现没有任何变化.我想这是由于ASP.NET Core托管模型的差异所致.

However, after adding this to my web.config on Azure, I observe no change. I imagine this is due to differences in ASP.NET Core's hosting model.

这是我当前的web.config:

<configuration>
    <system.web>
        <httpRuntime requestPathInvalidCharacters=""/>
        <pages validateRequest="false" />
    </system.web>
    <system.webServer>
        <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".\Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
    </system.webServer>
</configuration>

以及相关的控制器标头...

And the relevant controller header...

[HttpGet]
[Route("{serverIpAddress}/{serverPort}/{approxMatchStartTimeStr}")]
public IActionResult GetMatchEvents(string serverIpAddress, string serverPort, DateTimeOffset approxMatchStartTimeStr)
{
    ...
}

如何获取IIS/Azure以允许URL中使用冒号?

How can I get IIS/Azure to allow the colon character in URLs?

推荐答案

您遇到的问题与路径中的冒号(:)无关,它实际上是

The issue you're running into isn't related to the colon (:) in the path, it's really the plus (+) that IIS doesn't like. It doesn't matter if the plus is encoded as "+" or "%2B". You have two options:

  1. 将plus/DateTimeOffset从路径移动到IIS不介意的查询字符串.
  2. 将IIS请求过滤模块配置为"allowDoubleEscaping".

示例web.config:

Example web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <security>
            <requestFiltering allowDoubleEscaping="true" />
        </security>
        <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath="dotnet" arguments=".\Server.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
    </system.webServer>
</configuration>

当前web.config的system.web部分与ASP.NET Core无关.

The system.web section of your current web.config isn't relevant to ASP.NET Core.

这篇关于在IIS/Azure中的ASP.NET Core的URL中允许冒号(:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆