(原创)无需修改IIS在.NET2005中实现无扩展名的URL重写
2008-02-20 11:12
513 查看
此篇文章感谢福娃儿,在他的文章基础上加以改进
当在程序中引入了ActionlessForm.dll,UrlRewriter.dll两个类库文件后
在Web.Config配置文件中,添加如下代码
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter"/>
</configSections>
<CustomConfiguration>
<urls>
<add virtualUrl="~/products/(.+).aspx" destinationUrl="~/products.aspx?ID=$1"/>
<add virtualUrl="~/(.+)/(.+)/(.+)/(.+).aspx" destinationUrl="~/products.aspx?ID=$1,$2,$3,$4"/>
<add virtualUrl="~/(.+)" destinationUrl="~/products.aspx?ID=$1"/>
</urls>
</CustomConfiguration>
<system.web>
<httpModules>
<add type="URLRewriter.RewriterModule, URLRewriter" name="RewriterModule"/>
</httpModules>
<authentication mode="Forms"/>
<compilation debug="true"/>
</system.web>
</configuration>
其中的<add virtualUrl="~/(.+)" destinationUrl="~/products.aspx?ID=$1"/>标记解释为
如果请求的虚地址www.abc.com/任何字符,均被定向到www.abc.com/products.aspx?ID=任何字符
这样,就可以实现BLOG中的blog.abc.com/fushuai效果了
OK,建立个Products.aspx,Default.aspx页面
在Default上写个链接
<asp:HyperLink ID="HyperLink9" runat="server" NavigateUrl="~/2008/2/21/Car.aspx">2008/2/21/Car.aspx</asp:HyperLink><br />
<asp:HyperLink ID="HyperLink10" runat="server" NavigateUrl="~/products/Car.aspx">products/Car.aspx</asp:HyperLink><br />
<asp:HyperLink ID="HyperLink11" runat="server" NavigateUrl="~/fushuai">无扩展名fushuai</asp:HyperLink><br />
然后在Products的PageLoad里写
if (!IsPostBack)
...{
Response.Write(Request["ID"]);
}
运行下就能看到效果了
希望对初学Url重写的朋友会有所帮助,多多交流啊
如果发现有什么问题,也希望及时给我提出意见,共同进步啦
当在程序中引入了ActionlessForm.dll,UrlRewriter.dll两个类库文件后
在Web.Config配置文件中,添加如下代码
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="CustomConfiguration" type="URLRewriter.Config.UrlsSection, URLRewriter"/>
</configSections>
<CustomConfiguration>
<urls>
<add virtualUrl="~/products/(.+).aspx" destinationUrl="~/products.aspx?ID=$1"/>
<add virtualUrl="~/(.+)/(.+)/(.+)/(.+).aspx" destinationUrl="~/products.aspx?ID=$1,$2,$3,$4"/>
<add virtualUrl="~/(.+)" destinationUrl="~/products.aspx?ID=$1"/>
</urls>
</CustomConfiguration>
<system.web>
<httpModules>
<add type="URLRewriter.RewriterModule, URLRewriter" name="RewriterModule"/>
</httpModules>
<authentication mode="Forms"/>
<compilation debug="true"/>
</system.web>
</configuration>
其中的<add virtualUrl="~/(.+)" destinationUrl="~/products.aspx?ID=$1"/>标记解释为
如果请求的虚地址www.abc.com/任何字符,均被定向到www.abc.com/products.aspx?ID=任何字符
这样,就可以实现BLOG中的blog.abc.com/fushuai效果了
OK,建立个Products.aspx,Default.aspx页面
在Default上写个链接
<asp:HyperLink ID="HyperLink9" runat="server" NavigateUrl="~/2008/2/21/Car.aspx">2008/2/21/Car.aspx</asp:HyperLink><br />
<asp:HyperLink ID="HyperLink10" runat="server" NavigateUrl="~/products/Car.aspx">products/Car.aspx</asp:HyperLink><br />
<asp:HyperLink ID="HyperLink11" runat="server" NavigateUrl="~/fushuai">无扩展名fushuai</asp:HyperLink><br />
然后在Products的PageLoad里写
if (!IsPostBack)
...{
Response.Write(Request["ID"]);
}
运行下就能看到效果了
希望对初学Url重写的朋友会有所帮助,多多交流啊
如果发现有什么问题,也希望及时给我提出意见,共同进步啦
相关文章推荐
- 使用Microsoft URL Rewrite Module for IIS 7.0修改WEB.CONFIG即可实现*.HTML伪静态 无需修改应用程序映射
- 在ASP.NET中重写URL 方法四:在IIS5和IIS6中使用 ISAPIRewrite 来实现无扩展名的URL重写
- IIRF(Ionics Isapi Rewrite Filt er)实现在IIS 5/6上重写Url
- IIRF(Ionics Isapi Rewrite Filt er)实现在IIS 5/6上重写Url
- 没有为扩展名“.html”注册的生成提供程序。.net urlwrite 重写 伪静态 IIs 配置
- iis重写模块实现程序自动二级域名,微软提供的URL重写2.0版本适用IIS以上
- 没有为扩展名“.html”注册的生成提供程序。.net urlwrite 重写 伪静态 IIs 配置
- 修改apache的重写机制,实现url的重写模式
- IIRF(Ionics Isapi Rewrite Filt er)实现在IIS 5/6上重写Url
- IIS下配置页面重写(配合插件url-rewrite2去除页面后缀名)的实现方法
- 没有为扩展名“.html”注册的生成提供程序。.net urlwrite 重写 伪静态 IIs 配置
- URL重写之在IIS7中使用HttpModule,在IIS5和IIS6中使用 ISAPIRewrite实现无扩展名的URL重写(节选自福娃儿)
- 不使用ISAPI或IIS wildcard实现不带扩展名URL的转向
- asp.net下实现URL重写伪静态之iis设置
- 在ASP.NET中重写URL 方法三:在IIS7中使用HttpModule 实现无扩展名的URL重写
- 不使用ISAPI或IIS wildcard实现不带扩展名URL的转向
- Asp.Net中通常不修改IIS实现URL重写,支持任意扩展名及无扩展名(伪静态)
- Python3.5编程实现修改IIS WEB.CONFIG的方法示例
- [原创]java WEB学习笔记26:MVC案例完整实践(part 7)---修改的设计和实现
- url重写URLReWriter实现任意二级域名