微软自带的 URLRewriter类库
在Web.config中
<httpHandlers>
path="*.aspx" 调试正常RewriterFactoryHandler IHttpModule接口里也没有限制必须为.ASPX
add属性 path="*.html"
修改 <LookFor>~/Products/Dairy\.html</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=4</SendTo>
调试时 进入不了RewriterFactoryHandler类
已在IIS aspnet_isapi.dll 中添加了 .html 扩展名 不去判断 文件是否存在
为什么不能重写成.HTML
------------------------------------------------------------------------
在Web.config中
<httpHandlers>
path="*.aspx" 调试正常RewriterFactoryHandler IHttpModule接口里也没有限制必须为.ASPX
add属性 path="*.html"
修改 <LookFor>~/Products/Dairy\.html</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=4</SendTo>
调试时 进入不了RewriterFactoryHandler类
已在IIS aspnet_isapi.dll 中添加了 .html 扩展名 不去判断 文件是否存在
为什么不能重写成.HTML
------------------------------------------------------------------------
解决方案 »
- 有关ajax的问题(在updatePanel中动态添加控件的问题)
- 如何让按钮在单击后直接执行click事件里面的代码,而不执行Page_Load中的代码
- 牛人救命啊!如何取到Label1 .Attributes.Add ("onclick","return confirm('确认吗?');")的返回值
- DataGrid1删除一行,出错 “未将对象引用设置到对象的实例。行 106: dSet.Tables("Tb_ResOrderDetail").Rows(e.Item.ItemIndex).Delete(
- Asp.net2.0如何using System.Data.Oledb
- 怎么把treeview已有的内容清空,刷新时重新绑定!
- 如何设置treeview控件中当鼠标移到(点击)节点时节点文字的显示颜色?(在线等待!)
- 存储过程
- ju_feng高手请指教。
- 如何将webform里面查询结果的dataset传递到crystal Report里面!100分!
- 分页问题!!!请大虾帮帮忙!
- 有没有人做过监控应用程序方面的东东?给点思路
http://www.51aspx.com/S/urlrewrite.aspx
<configuration>
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>第二步,加入重写的规则节点:
如:
<RewriterConfig>
<Rules>
<RewriterRule>
<LookFor>~/Sell/(.[0-9]*)\.html</LookFor>
<SendTo>~/Search/Search_Sell.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Sell/Search_Sell\.aspx</LookFor>
<SendTo>~/Search/Search_Sell.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Buy/(.[0-9]*)\.html</LookFor>
<SendTo>~/Search/Search_Buy.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Buys/(.[0-9]*)\.html</LookFor>
<SendTo>~/Buys/Show.aspx?id=$1</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>这个就要根据你的需要了,如果你对正则表达式不熟,那么没办法,要么凭借你的高智商去找其中规律,稍稍改一下就能为你所用了。呵呵。如果实在搞不清,那就自己GOOGLE一下正则表达式吧。(本人开始是参考别人的配置猜的,竟然用对了,呵呵。后来还是看了一下相关资料,发现这东东很有用。)第三步,加入模块配置(写在<system.web>里面):
如:
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
(这里表示使用HTTP程序来处理重写)好了,到了现在我们可以试一下看。于是输入:http://127.0.0.1:8080/Sell/1.aspx 出现了,呵呵。但是如果所它改为:http://127.0.0.1:8080/Sell/1.html
晕,发现不行。汗
呵呵,原因是没把HTML的解析用 asp.net 的ISAPI来解析。
办法是第四步,在IIS\你的站点\属性\主目录\配置\映谢 加入一个和 aspx 页面的配置相同的扩展名项。注意“确认文件是否存在”不要勾选,否则会出现找不到文件。现在再来试试看。什么?#¥%#¥%#,还是不行。呵呵。不要急,咱们回过头再来看看,原来在 web.config 中我们没有配置 .html 也使用模块此解析。第五步,在模块配置中加入:
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>现在总可以了吧,呵呵。终于看到了,兴奋吧。不要急,这还只是最简单的。如果你的页面有回传。比如说放了DATAGRID,有分页的,你点到下一页就发现,晕倒,又出问题了。
这下怎么办呢,这个其实微软件的网站上就有说到,我在这里简述一下了。
第六步,加入窗体回传保持的组件:
在原来你下载的项目里找到 ActionlessForm.dll 放到你的项目 bin 目录下。然后在你的这个页面中加入:
<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
再把你的<Form...>改为:
<skm:Form id="你的表单名" method="post" runat="server">
.....
</skm:Form>That's All.现在你可以高枕无忧了。一切如你所愿。最后,恭祝各位一切顺利。
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
只是觉得郁闷 跟踪了2次 觉得改3个地方就行<LookFor> IIS <httpHandlers>
为什么改了HTML 运行时直接404错误
正则表达式>~/Products/Dairy\.html 应该HTTP://localhost/RewriterTester/Products/Dairy.html啊
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
问题解决
------------------------------------------------------------------------------
-.-|| 要写2个ADD 只要能进调试 我就能解决的 谢谢shaohaiou() huzhangyou
准备结帖子