asp.net2.0使用urlrewrite實現(xiàn)真正二級域名
發(fā)布時間:2009/5/4 8:46:37 作者: 閱讀:1598
廣告:
搞了一個多星期,今天二級域名總算正式可以使用了,回憶起來有以下幾步:
1.微軟網(wǎng)站下載urlrewrite組件:http://msdn2.microsoft.com/zh-cn/library/ms972974.aspx,下載下來,升級到asp.net2.0 ;
2. 修改urlrewrite項目代碼:① BaseModuleRewriter.cs類 中"app.Request.Path" 替換成"app.Request.Url.AbsoluteUri " ② ModuleRewriter.cs 類中" string lookFor = "^" + RewriterUtils.ResolveUrl(app.Context.Request.ApplicationPath, rules[i].LookFor) + "$" 改成 tring lookFor = "^" + rules[i].LookFor + "$" ";只取 "URLRewriter.dll" 加入現(xiàn)有項目bin目錄中
3.配置服務器,建一新網(wǎng)站,主機頭為空,目的為了使用泛域名;網(wǎng)站目錄指向要使用二級域名的網(wǎng)站;
IIS站點屬性 ->主目錄 -> 配置 -> 插入通配符應用程序映射,文件指向2.0下"aspnet_isapi.dll",并在確認該文件前去掉勾。
4.配置web.config文件如下。
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionH\"and\"ler, URLRewriter" />
</configSections>
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionH\"and\"ler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/default\.aspx</LookFor>
<SendTo>~/company/$1/</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/index\.html</LookFor>
<SendTo>~/company/$1/</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp</LookFor>
<SendTo>~/company/$1/$2.asp</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp\?(\w+)=(.+)</LookFor>
<SendTo>~/company/$1/$2.asp?$3=$4</SendTo>
</RewriterRule>
<!--<RewriterRule> 正確
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp\?id=(\d+)</LookFor>
<SendTo>~/company/$1/$2.asp?id=$3</SendTo>
</RewriterRule> 正確-->
</Rules>
</RewriterConfig>
<system.web>
<customErrors mode="Off"/>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<compilation debug="false" defaultLanguage="c#" />
</system.web>
</configuration>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/default\.aspx</LookFor>
<SendTo>~/company/$1/</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/index\.html</LookFor>
<SendTo>~/company/$1/</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp</LookFor>
<SendTo>~/company/$1/$2.asp</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp\?(\w+)=(.+)</LookFor>
<SendTo>~/company/$1/$2.asp?$3=$4</SendTo>
</RewriterRule>
<!--<RewriterRule> 正確
<LookFor>http\://(.*)\.1718vip\.com/(\w+)\.asp\?id=(\d+)</LookFor>
<SendTo>~/company/$1/$2.asp?id=$3</SendTo>
</RewriterRule> 正確-->
</Rules>
</RewriterConfig>
<system.web>
<customErrors mode="Off"/>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<compilation debug="false" defaultLanguage="c#" />
</system.web>
</configuration>
至此,基本上完成。
注意:如果不成功,80%是正則表達式?jīng)]寫好。
另外:
<RewriterRule>
<LookFor>http\://(.{4,10})\.epoll\.net\.cn/</LookFor>
<SendTo>~/$1/<sendTo>
</RewriterRule>
廣告:
相關(guān)文章