(原创)无需修改IIS在.NET2005中实现无扩展名的URL重写
来源:互联网 发布:xy传奇盛世翅膀数据 编辑:程序博客网 时间:2024/05/15 23:52
此篇文章感谢福娃儿,在他的文章基础上加以改进
当在程序中引入了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>
<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 />
<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"]);
}
...{
Response.Write(Request["ID"]);
}
运行下就能看到效果了
希望对初学Url重写的朋友会有所帮助,多多交流啊
如果发现有什么问题,也希望及时给我提出意见,共同进步啦
- (原创)无需修改IIS在.NET2005中实现无扩展名的URL重写
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI。
- ASP.net实现无扩展名的URL重写。简单、方便、无需ISAPI .
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名(伪静态)
- Asp.Net中通常不修改IIS实现URL重写,支持任意扩展名及无扩展名(伪静态)
- Asp.Net中不修改IIS实现URL重写,支持任意扩展名及无扩展名(伪静态)
- URL重写之在IIS7中使用HttpModule,在IIS5和IIS6中使用 ISAPIRewrite实现无扩展名的URL重写(节选自福娃儿)
- ASP.net实现无扩展名的URL重写(转)
- ASP.net实现无扩展名的URL重写
- C#,.Net经典面试题目及答案(转载)
- Java Lucene (2):分词器
- 网络业历史上最热闹的30大争论(2)
- SQL Server 2k 中非域环境下数据库的异机备份
- 史玉柱东山再起幕后高人:赚钱得克服贪欲
- (原创)无需修改IIS在.NET2005中实现无扩展名的URL重写
- 软件的最低测试方法
- 在windows上搭建linux开发环境
- 原码、反码和补码
- OSI的七层网络模型简要理解
- java.math.BigDecimal的用法
- java提出word和pdf等文件的信息
- 为应用开发辩护
- 常见错误:JavaScript 提交form 的时候,Error:对象不支持此属性或方法