配置web.config以将具有特定模式的URL重定向/转发到另一种模式(使用冒号和双斜杠)

问题描述 投票:1回答:1

我有一个旧的数据库,它返回带有ASP.NET应用程序中不存在的URL链接的hughe文本。链接看起来像这样:

قزكسصوب$علمنة://%7بخصث0س01-3974-49يخ-91د4-49بض43359557%حد

应该转变为:

http://bbmag295:7777/

这意味着应该选择“$ element://%7B”和“%7D”之间的模式并重定向到ShowGlossary.aspx?id = ...

我在C#中编写了以下RegMatch-Expression:

http://bbmag295:7777/ShowGlossary.aspx?id=57980C01-3974-49e5-91D4-49B843359557

我刚刚在Web.Config中尝试过这个但是我无法让匹配网址工作:

    string pattern2 = @"(element://{[^>]+})";

    MatchCollection matches2 = Regex.Matches(neuerString, pattern2);

    if (matches2.Count > 0)
    {
        foreach (Match m in matches2)
        {
            string toReplace = "$" + m.Groups[1].ToString();
            string guid = toReplace.ToString().Replace("$element://", "");

            neuerString = neuerString.Replace(toReplace, "ShowGlossary.aspx?id=" + guid); 

        }
    }

是否有可能://部件无法进行此类转发?冒号(:)导致错误为“潜在的危险请求”。 id能做什么?

最后我得到了它:

              <rewrite>
                <rules>
                  <rule name="Query String Rewrite">  
                    <!--<match url="(element://{[^>]+})" />-->
                    <!--<match url="^Article/([0-9]+)/([_0-9a-z-]+)" />-->
                    <!--<action type="Rewrite" url="ShowGlossary.aspx?ID={R:1}"/>  -->
                    <!--<match url="^Article/([0-9]+)/([_0-9a-z-]+)" />-->
                    <match url="^\$element://([_0-9a-z-]+)" />
                    <action type="Rewrite" url="ShowGlossary.aspx?id={R:1}" />
                  </rule>      
                </rules>
              </rewrite>

1.)将requestPathInvalidCharacters设置为“”2.)3。)

我的下一个问题是,重写后没有加载样式:'(

asp.net iis web-config
1个回答
0
投票

最后,我使用重定向而不是重写它。

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>
  <system.webServer>
  <security> 
       <requestFiltering allowHighBitCharacters="true" allowDoubleEscaping="true" /> 
  </security>
  <rewrite>
    <rules>
      <rule name="Query String Rewrite">  
        <match url="^\$element:/\{([_0-9a-z-]+)\}" />
        <action type="Rewrite" url="ShowGlossary.aspx?id={R:1}" />
      </rule>      
    </rules>
  </rewrite>
  </system.webServer>
    <connectionStrings>
        <add name="EAPFile" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=~MDB/plm.eap" providerName="System.Data.SqlClient" />
        <add name="plmConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" providerName="System.Data.OleDb" />
    </connectionStrings>
    <system.web>
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" requestPathInvalidCharacters=""/>
      <pages validateRequest="false" />
    </system.web>
    <system.web.extensions>
      <scripting>
        <webServices>
          <jsonSerialization maxJsonLength="50000000"/>
        </webServices>
      </scripting>
    </system.web.extensions>
</configuration>

之后,我不得不下载重写模块,否则我在IIS中得到错误500(在Visual Studio中它已经工作了一整天)

© www.soinside.com 2019 - 2024. All rights reserved.