100求一个URL重写的实际例子(URLRewriting) 100求一个URL重写的实际例子(URLRewriting) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://www.kfnet.cn/Artical.kf?ArticalID=1739&Belong=0&Type=1 (有例子)http://www.cnblogs.com/coollzh/archive/2004/12/11/75471.htmlhttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/urlrewriting.asphttp://dottextwiki.scottwater.com/default.aspx/Dottext.UrlRewriting http://www.microsoft.com/china/msdn/library/webservices/asp.net/URLRewriting.mspx <?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" /> </configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/News/c(\d{1,5})\.aspx</LookFor> <SendTo>~/News/NewsList.aspx?Cat_ID=$1</SendTo> </RewriterRule> <RewriterRule> <LookFor>~/News/d(\d+)\.aspx</LookFor> <SendTo>~/News/NewsDetails.aspx?News_ID=$1</SendTo> </RewriterRule> </Rules> </RewriterConfig> <system.web> <httpModules> <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" /> </httpModules> <compilation defaultLanguage="c#" debug="true" /> <customErrors mode="RemoteOnly" /> <authentication mode="Windows" /> <authorization> <allow users="*" /> </authorization> <trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" /> <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false" timeout="20" /> <globalization requestEncoding="utf-8" responseEncoding="utf-8" /> </system.web></configuration>分析器错误信息: 找不到文件或程序集名称“URLRewriter”,或找不到它的一个依赖项。源错误: 行 18: <system.web>行 19: <httpModules>行 20: <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />行 21: </httpModules>行 22: <compilation defaultLanguage="c#" debug="true" /> 先取得地址在修改後重定向!string url = this.Request.Url.ToString(); //取得url = url.Replace("index1.aspx","index.aspx");//修改Page.Response.Redirect(url); //蟲定向這是我用到的一個方法! 我不太明白<RewriterConfig>我的应用有是例如十位的编码例如:0000000001.请问<RewriterRule>怎么写. 配置:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.aspx</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>完成:http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.aspx之间的转换我想完成http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.html之间的转换修改:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.html</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>为什么无效呢?我的机器是Server2003的.请问是不是要配置什么???? 配置:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.aspx</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>完成:http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.aspx之间的转换我想完成http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.html之间的转换修改:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.html</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>为什么无效呢?我的机器是Server2003的.请问是不是要配置什么????最后的一个小问题了.◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆ 配置:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.aspx</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>完成:http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.aspx之间的转换我想完成http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133http://localhost/Test4RewriteUrl/0000000133.html之间的转换修改:<RewriterConfig> <Rules> <RewriterRule> <LookFor>~/(\d{10})\.html</LookFor> <SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo> </RewriterRule> </Rules></RewriterConfig>为什么无效呢?我的机器是Server2003的.请问是不是要配置什么????最后的一个小问题了.◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆ 如果重写为其他的类型,IIS中需要添加请求的驱动为aspnetapi. 打开 Global.asax.cs 在最上面添加一行 using System.Text.RegularExpressions;然后在 Application_BeginRequest 事件中写入 string strRawUrl = HttpContext.Current.Request.RawUrl; string strNewUrl; if (Regex.IsMatch(strRawUrl, @"default.aspx", RegexOptions.IgnoreCase)) { strNewUrl = Regex.Replace(strRawUrl, @"default.aspx", @"showforum.aspx\?fld=1"); HttpContext.Current.RewritePath( strNewUrl ); } else if (Regex.IsMatch(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", RegexOptions.IgnoreCase)) { strNewUrl = Regex.Replace(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", @"showtopic.aspx\?tid=$1&tpg=$2&bpg=$3&fld=$4"); HttpContext.Current.RewritePath( strNewUrl ); } else if (Regex.IsMatch(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", RegexOptions.IgnoreCase)) { strNewUrl = Regex.Replace(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", @"$10$20$30$4.html"); HttpContext.Current.Response.Redirect( strNewUrl ); }第一个IF是最最简单的第二个IF是当IIS把HTML交给ASP.NET时使用的,嘿嘿第三个IF是为了解决表单提交时IE的地址栏出现真实的URL地址,是第二个IF的逆操作其中正则表达式里的0是分隔符,因为页数、ID的最小址都不可能是0用户IE的地址栏中显示的是http://localhost/AdNT/4561230100101.html但实际上是http://localhost/AdNT/showtopic.aspx?tid=456123&tpg=10&bpg=1&fld=1楼主,我说的清楚么?^^ 如果是把重写规则保存XML文件里,可以直接用DataSet读取出来,然后用for循环,找到了匹配的就跳出来 忘记说,楼主记得要把DataSet缓存,不然每次都要读取XML倒,三连了…… datagrid单元格颜色问题 请高人指教一下,我想做一个插件,,一点头绪都没有... Request.Form[4]的疑问? 页面回退的 问题 请问一下,我这段语句错在那里 借这里的人气一用。 关于禁止拷屏 数据绑定问题 Js与.Net结合怎么用? 关于web.config的问题 讨厌的.aspx 文件重编译问题 freetextbox1.63版的文章粘贴问题,跟实际页面显示的不一样,请班竹指教,谢谢?!
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/News/c(\d{1,5})\.aspx</LookFor>
<SendTo>~/News/NewsList.aspx?Cat_ID=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/News/d(\d+)\.aspx</LookFor>
<SendTo>~/News/NewsDetails.aspx?News_ID=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
<system.web>
<httpModules>
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
</httpModules>
<compilation defaultLanguage="c#" debug="true" />
<customErrors mode="RemoteOnly" />
<authentication mode="Windows" />
<authorization>
<allow users="*" />
</authorization>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true" />
<sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes"
cookieless="false" timeout="20" />
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</configuration>
分析器错误信息: 找不到文件或程序集名称“URLRewriter”,或找不到它的一个依赖项。源错误:
行 18: <system.web>
行 19: <httpModules>
行 20: <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
行 21: </httpModules>
行 22: <compilation defaultLanguage="c#" debug="true" />
string url = this.Request.Url.ToString(); //取得
url = url.Replace("index1.aspx","index.aspx");//修改
Page.Response.Redirect(url); //蟲定向
這是我用到的一個方法!
我的应用有是例如十位的编码例如:0000000001.请问<RewriterRule>
怎么写.
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.aspx</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
完成:
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.aspx
之间的转换我想完成
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.html
之间的转换
修改:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.html</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>为什么无效呢?
我的机器是Server2003的.
请问是不是要配置什么????
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.aspx</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
完成:
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.aspx
之间的转换我想完成
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.html
之间的转换
修改:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.html</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>为什么无效呢?
我的机器是Server2003的.
请问是不是要配置什么????
最后的一个小问题了.
◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.aspx</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
完成:
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.aspx
之间的转换我想完成
http://localhost/Test4RewriteUrl/ShopTopic.aspx?TI_SN=0000000133
http://localhost/Test4RewriteUrl/0000000133.html
之间的转换
修改:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/(\d{10})\.html</LookFor>
<SendTo>~/ShopTopic.aspx?TI_SN=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>为什么无效呢?
我的机器是Server2003的.
请问是不是要配置什么????
最后的一个小问题了.
◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
string strNewUrl; if (Regex.IsMatch(strRawUrl, @"default.aspx", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"default.aspx", @"showforum.aspx\?fld=1"); HttpContext.Current.RewritePath( strNewUrl );
}
else if (Regex.IsMatch(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"(\d+)0(\d+)0(\d+)0(\d+).html", @"showtopic.aspx\?tid=$1&tpg=$2&bpg=$3&fld=$4"); HttpContext.Current.RewritePath( strNewUrl );
}
else if (Regex.IsMatch(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"showtopic.aspx\?tid=(\d+)&tpg=(\d+)&bpg=(\d+)&fld=(\d+)", @"$10$20$30$4.html"); HttpContext.Current.Response.Redirect( strNewUrl );
}第一个IF是最最简单的第二个IF是当IIS把HTML交给ASP.NET时使用的,嘿嘿第三个IF是为了解决表单提交时IE的地址栏出现真实的URL地址,是第二个IF的逆操作其中正则表达式里的0是分隔符,因为页数、ID的最小址都不可能是0
用户IE的地址栏中显示的是http://localhost/AdNT/4561230100101.html
但实际上是http://localhost/AdNT/showtopic.aspx?tid=456123&tpg=10&bpg=1&fld=1楼主,我说的清楚么?^^