【问题标题】:How to Configure UrlRewritingNet on the server side IIS 7 Windows 7 Server如何在服务器端 IIS 7 Windows 7 Server 上配置 UrlRewritingNet
【发布时间】:2013-05-17 07:34:29
【问题描述】:

经过测试,我已经完成了一个 ASP.NET 网站。

我正在使用来自http://www.urlrewriting.net/ 的 UrlRewritingNet dll

然后我发布了它以上传我的服务器(安装了 Windows 7、IIS 7)。输入我网站的 URL 后,我得到 404 - Not found 错误。这是因为服务器端的配置缺失或错误。但我不知道该怎么做。

搜索了很多次,但找不到任何接近我的问题的东西。

最后一次机会,我在这里。你能帮忙吗?

你可以在下面看到我的 web.config 内容:

<?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>
    <configSections>
        <section name="urlrewritingnet" requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"/>
    </configSections>

<system.web>
        <httpModules>
            <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
        </httpModules>

        <compilation debug="true" targetFramework="4.0"/>
    </system.web>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>

        <handlers>
            <remove name="PageHandlerFactory-ISAPI-4.0_32bit"/>

            <add name="PageHandlerFactory-ISAPI-4.0_32bit" path="*.aspx" verb="GET,HEAD,POST,DEBUG" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0"/>

            <add name="reww" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>

            <add name="rewwibu" path="*.ibu" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness32"/>
        </handlers>

        <validation validateIntegratedModeConfiguration="false"/>
    </system.webServer>

    <urlrewritingnet configSource="ExternalRewrite.config"/>
</configuration>

这是我的新 Web.Config 文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <validation validateIntegratedModeConfiguration="false" />
        <rewrite>
            <rules>
                <rule name="GoAnasayfa">
                    <match url="^([_0-9a-z-]+)/Anasayfa.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="Default.aspx?lang={R:1}" appendQueryString="false" />
                </rule>
                <rule name="GoIletisim">
                    <match url="^([_0-9a-z-]+)/Iletisim.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="Contact.aspx?lang={R:1}" />
                </rule>
                <rule name="GoDereceProgramlari">
                    <match url="^([_0-9a-z-]+)/DereceProgramlari/([_0-9a-z-]+).ibu" ignoreCase="false" />
                    <action type="Rewrite" url="DegreePrograms.aspx?lang={R:1}&amp;derece={R:2}" />
                </rule>
                <rule name="GoOgrenci">
                    <match url="^([_0-9a-z-]+)/Ogrenci.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="Ogrenci.aspx?lang={R:1}" />
                </rule>
                <rule name="GoKatalog">
                    <match url="^([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([0-9])/Katalog.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="Catalog.aspx?lang={R:1}&amp;opID={R:2}&amp;pmID={R:3}&amp;oid={R:4}" />
                </rule>
                <rule name="GoDersDetay">
                    <match url="^([_0-9a-z-]+)/([0-9]+)/([0-9]+)/([0-9])/([0-9])/DersAyrintilari.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="CourseDetail.aspx?lang={R:1}&amp;opID={R:2}&amp;pmID={R:3}&amp;DersID={R:4}&amp;dersKodu={R:5}" />
                </rule>
                <rule name="GoLLPKoordinatorleri">
                    <match url="^([_0-9a-z-]+)/LLPKoordinatorleri.ibu" ignoreCase="false" />
                    <action type="Rewrite" url="Coordinators.aspx?lang={R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

当我输入我的网址时,地址栏会填满 lang 参数,如下所示:

http://somedomain.com/tr-TR/Anasayfa.ibu?lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr&lang=tr-tr....

然后浏览器显示错误信息:

无效的重定向网址

【问题讨论】:

  • 我不是最擅长正则表达式,但您应该考虑将您的正则表达式从 ^([_0-9a-z-]+) 更改为 [a-z][a-z]-[A-Z][A-Z]。这将只允许格式为 en-UStr-TR 的 lang,其中前两个字母是小写字母,后两个字母是大写字母。您可能希望忽略大小写,以便在正则表达式中添加 or 条件,以查找除大写字母之外的小写字母 a-z。

标签: asp.net windows-7 iis-7 url-rewriting


【解决方案1】:

尝试添加:

<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
<remove name="Session"/>
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>

到您的 web.config

<configuration>
  ...
  <system.webServer>
    ... 
    <modules>
      <!-- add here -->
    </modules>
  </system.webServer>
  ...
</configuration>

【讨论】:

  • 这对我有用。不确定发生了什么变化,我们不想重做我们的网站。谢谢!!
  • 升级 .NET 框架时,模块条目有时会在 Visual Studio 中消失。
【解决方案2】:

为什么不使用微软的 URL 重写模块?
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

请务必根据您的系统设置安装正确的版本。然后您可以继续创建重写规则,如下所示:
http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

【讨论】:

  • 谢谢。这就是我真正想要的。我还想知道是否可以将规则写入 .config 文件,而不是在服务器上的 IIS 中写入。因为这次我有机会配置服务器,但将来我不会。 +1
  • 我打开了我的 web.config 并得到了答案。 (:
  • 很高兴能帮上忙。
  • 规则写法我很清楚。现在我收到 404 错误。例如:我的网站的打开页面是somedomain.com/Default.aspx?lang=en-US,我将其改写为somedomain.com/en-US/Home.ibu,但服务器正在寻找en-US文件夹。
  • 你能发布你的重写规则吗?
猜你喜欢
  • 2012-04-13
  • 2011-08-10
  • 2012-09-23
  • 1970-01-01
  • 2010-09-18
  • 1970-01-01
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
相关资源
最近更新 更多