UrlRewriting在服务器上不起作用,但在localhost上它在asp.net上工作正常吗?

时间:2016-06-26 09:32:48

标签: asp.net asp.net-web-api url-rewriting seo webforms-routing

 <urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage="default.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
    <rewrites>
      <add name="book" virtualUrl="^~/book/(.*?)/([0-9]+)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/book.aspx?title=$1&amp;id=$2" ignoreCase="true" processing="stop" />
      <add name="page" virtualUrl="^~/page/(.*?)/([0-9]+)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/page/default.aspx?title=$1&amp;id=$2" ignoreCase="true" processing="stop" />
      <add name="register" virtualUrl="^~/register/(.*?)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/register.aspx?title=$1" ignoreCase="true" processing="stop" />
      <add name="login" virtualUrl="^~/login$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/login.aspx" ignoreCase="true" processing="stop" />
      <add name="download" virtualUrl="^~/download/(.*?)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/download.aspx?title=$1" ignoreCase="true" processing="stop" />
      <add name="forgotpass" virtualUrl="^~/passwordrecovery$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/forgotPassword.aspx" ignoreCase="true" processing="stop" />
      <add name="newsarchive" virtualUrl="^~/news-archive$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/newsarchive.aspx" ignoreCase="true" processing="stop" />
      <add name="newsarchivekeywords" virtualUrl="^~/news-archive/(.*?)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/newsarchive.aspx?title=$1" ignoreCase="true" processing="stop" />
      <add name="news" virtualUrl="^~/news/(.*?)/([0-9]+)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/news.aspx?title=$1&amp;id=$2" ignoreCase="true" processing="stop" />
      <add name="articlearchive" virtualUrl="^~/article-archive$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/articlearchive.aspx" ignoreCase="true" processing="stop" />
      <add name="articlearchivekeywords" virtualUrl="^~/article-archive/(.*?)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/articlearchive.aspx?title=$1" ignoreCase="true" processing="stop" />
      <add name="article" virtualUrl="^~/article/(.*?)/([0-9]+)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/article.aspx?title=$1&amp;id=$2" ignoreCase="true" processing="stop" />
      <add name="search" virtualUrl="^~/search/(.*?)$" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/search.aspx?s=$1" ignoreCase="true" processing="stop" />
    </rewrites>
  </urlrewritingnet>

这是我的web.config代码。 evry的东西在localhost(iis)中可以,但是当我发布到服务器时。我刚拿到这个

404 - 找不到文件或目录。 您要查找的资源可能已被删除,名称已更改或暂时不可用。

1 个答案:

答案 0 :(得分:0)

只是尝试将此添加到您的we.config并且问题已解决

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