Azure websites throw 500 error when there is a colon in the URL

删除回忆录丶 提交于 2019-12-05 05:35:50
Lukas Kabrt

If you are running a .NET application, then this is caused by ASP.NET HTTP runtime, more specifically by its request filtering feature.

If the URL path contains any of the disallowed characters (<,>,*,%,&,:,\\,?), the runtime throws the exception and because of the exception the IIS returns error code 500.

System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (:).

You can configure disallowed characters in your web.config file.

<system.web>
    <httpRuntime targetFramework="4.5" requestPathInvalidCharacters="*,%" />
</system.web>

But i would be careful, because there might be some security implications of such change.

Using the KUDU Console in Azure add the file applicationhost.xdt to D:\home\site.

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-   Transform">
 <system.applicationHost>
<sites>
  <site name="%XDT_SITENAME%" xdt:Locator="Match(name)">
           <virtualDirectoryDefaults xdt:Transform="Insert" allowSubDirConfig="false" />
           </site>
</sites>

This does the job, but has an unfortunate side effect, in that any web.config in any application subdirectory was ignored. For our side, this had the effect of not loading any static files which meant the site did not work properly.

This will work fine for any site having a single web.config at root level.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!