URL Rewrite
DNN提供两种URL Rewrite的方法
第一种方式请看二十四画生的介绍,它是通过在SiteUrls.config定义正则表达式实现的URL转换,如:
一旦覆写了方法,就可以在web.config中增加新的定义,如:
第一种方式请看二十四画生的介绍,它是通过在SiteUrls.config定义正则表达式实现的URL转换,如:
1<?xml version="1.0" encoding="utf-8" ?>
2<RewriterConfig>
3 <Rules>
4 <RewriterRule>
5 <LookFor>.*/TabId/(\d+)(.*)/Logoff.aspx</LookFor>
6 <SendTo>~/Admin/Security/Logoff.aspx?tabid=$1</SendTo>
7 </RewriterRule>
8 <RewriterRule>
9 <LookFor>.*/TabId/(\d+)(.*)/rss.aspx</LookFor>
10 <SendTo>~/rss.aspx?TabId=$1</SendTo>
11 </RewriterRule>
12 <RewriterRule>
13 <LookFor>.*/TabId/(\d+)(.*)</LookFor>
14 <SendTo>~/Default.aspx?TabId=$1</SendTo>
15 </RewriterRule>
16 </Rules>
17</RewriterConfig>
2<RewriterConfig>
3 <Rules>
4 <RewriterRule>
5 <LookFor>.*/TabId/(\d+)(.*)/Logoff.aspx</LookFor>
6 <SendTo>~/Admin/Security/Logoff.aspx?tabid=$1</SendTo>
7 </RewriterRule>
8 <RewriterRule>
9 <LookFor>.*/TabId/(\d+)(.*)/rss.aspx</LookFor>
10 <SendTo>~/rss.aspx?TabId=$1</SendTo>
11 </RewriterRule>
12 <RewriterRule>
13 <LookFor>.*/TabId/(\d+)(.*)</LookFor>
14 <SendTo>~/Default.aspx?TabId=$1</SendTo>
15 </RewriterRule>
16 </Rules>
17</RewriterConfig>
第二种方法使用FriendlyUrlProvider实现,它存在于DotNetNuke.Services.Url.FriendlyUrl名称空间下,提供四种抽象方法
1Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String) As String
2 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String) As String
3 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String, ByVal settings As PortalSettings) As String
4 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String, ByVal portalAlias As String) As String
2 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String) As String
3 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String, ByVal settings As PortalSettings) As String
4 Public MustOverride Function FriendlyUrl(ByVal tab As TabInfo, ByVal path As String, ByVal pageName As String, ByVal portalAlias As String) As String
一旦覆写了方法,就可以在web.config中增加新的定义,如:
1<friendlyUrl defaultProvider=”CustomFriendlyUrl”>
2<providers>
3 <clear/>
4 <add name=”DNNFriendlyUrl” type=”DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider,DotNetNuke.HttpModules.UrlRewrite”/>
5 <add name=”CustomFriendlyUrl” type=”CompanyName.FriendlyUrlProvider,CompanyName.FriendlyUrlProvider” />
6</providers>
7</friendlyUrl>
2<providers>
3 <clear/>
4 <add name=”DNNFriendlyUrl” type=”DotNetNuke.Services.Url.FriendlyUrl.DNNFriendlyUrlProvider,DotNetNuke.HttpModules.UrlRewrite”/>
5 <add name=”CustomFriendlyUrl” type=”CompanyName.FriendlyUrlProvider,CompanyName.FriendlyUrlProvider” />
6</providers>
7</friendlyUrl>