dotnet/aspnetcore

Add support for PATH_INFO server variable

Open

#6,006 创建于 2018年3月8日

在 GitHub 查看
 (4 评论) (2 反应) (0 负责人)C# (10,653 fork)batch import
area-middlewareenhancementhelp wanted

仓库指标

Star
 (37,933 star)
PR 合并指标
 (平均合并 16天 9小时) (30 天内合并 258 个 PR)

描述

Hi there,

Can you please provide support for the PATH_INFO server variable on IIS. I'm trying to migrate my legacy MVC website to the new one I've built ASP.Net Core. I'm trying to migrate the URL rewrite rules but they don't work as they rely on the PATH_INFO server variable.

I get the following error when trying to run my application: Unrecognized parameter type: 'PATH_INFO', terminated at string index: '10' Microsoft.AspNetCore.Rewrite.Internal.IISUrlRewrite.ServerVariables.FindServerVariable(string serverVariable, ParserContext context, UriMatchPart uriMatchPart)

Extract from my configure method in startup.cs which reads in an xml file:

using (StreamReader iisUrlRewriteStreamReader =
    File.OpenText("IISUrlRewrite.xml"))
            {
                var options = new RewriteOptions()
                    .AddIISUrlRewrite(iisUrlRewriteStreamReader);

                app.UseRewriter(options);
            }

The example content of the IISUrlRewrite,xml file is:

<rewrite>
  <rules>
    <rule name="Redirect /foo to foo2" stopProcessing="true">
      <match url=".*" />
      <conditions>
        <add input="{PATH_INFO}" pattern="^/foo$" />
      </conditions>
      <action type="Redirect" url="http://www.foo2.co.uk" appendQueryString="false" />
    </rule>
  </rules>
</rewrite>

If I change {PATH_INFO} to {QUERY_STRING}, the application loads but this isn't the redirect I need. Can you please provide support for this ASAP please?

In the meantime, is there a workaround I can use that will support {PATH_INFO} patterns on IIS?

Thanks

贡献者指南