2015-10-13 71 views
0

一个特定的页面我要添加打开下面的页面 http://test.com/Collection.aspx?title=Women追加查询字符串在重写规则的Web.config

http://tests.com/Women

http://tests.com/Collection.aspx?title=Women

as

http://test.com/pathann

我试图使用下面的重写规则,但这些工作的所有页面,我只是想实现这个特定的部分。

<rule name="RedirectUserFriendlsssyURL1" stopProcessing="true"> 
     <match url="^Collection\.aspx$" /> 
     <conditions> 
     <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
     <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" /> 
     </conditions> 
     <action type="Redirect" url="{C:1}" appendQueryString="false" /> 
    </rule> 
     <rule name="RewriteUserFriendlyURL1" stopProcessing="true"> 
     <match url="^([^/]+)/?$" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Collection.aspx?title={R:1}" /> 
    </rule> 

请帮我,我该如何做这些特定页面只。其实如果我申请所有页面,它会阻止其他一些功能的工作。

回答

1

我会在你的情况做的是只重定向的部分留到URL重写模块:通过在Global.asax的路由

<rule name="RedirectUserFriendlsssyURL1" stopProcessing="true"> 
    <match url="^Collection\.aspx$" /> 
    <conditions> 
    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /> 
    <add input="{QUERY_STRING}" pattern="^title=([^=&amp;]+)$" /> 
    </conditions> 
    <action type="Redirect" url="{C:1}" appendQueryString="false" /> 
</rule> 

和处理的其余部分:

void Application_Start(object sender, EventArgs e) 
{ 
    RegisterRoutes(RouteTable.Routes); 
} 

void RegisterRoutes(RouteCollection routes) 
{ 
    routes.MapPageRoute("CollectionRoute", 
     "{title}", 
     "~/Collection.aspx", false, 
     new RouteValueDictionary(), 
     //Here you can define the regex pattern to match the title phrases 
     new RouteValueDictionary { 
      { "title", "(women)|(pathann)" } 
     }); 
} 

但是,当然,如果您仍然倾向于保留通过url重写模块处理的所有内容,您可以像这样定义规则:

<rule name="RewriteUserFriendlyURL1" stopProcessing="true"> 
     <match url="(women)|(pathann)" /> 
     <conditions> 
     <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
     <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
     </conditions> 
     <action type="Rewrite" url="Collection.aspx?title={R:1}" /> 
</rule>