web.config的配置(一)
来源:互联网 发布:mac 设置输入法皮肤吗 编辑:程序博客网 时间:2024/05/19 20:44
使用URLRewriter实现URL重写
优点
1)隐藏真实URL,提高安全性
2)更加友好的URL,好记(看博客园就行知道啦)
3)便于搜素引擎收录
.........
可能的缺点
使用URL重写可能导致:
1)图片路径的问题
2)CSS路径的问题
3)性能问题
.........
先下载DLL包,附带了源码的.
download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi
URLRewriter.dll和ActionlessForm.dll
或者只使用DLL 本人已经上传:http://files.cnblogs.com/yun_shuai/URLRewriter.rar 含有上面2个DLL
使用方法 :WEB项目中添加引用
webconfig中配置:
1 <configSections> 节点中增加:
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"/>
2 <configuration>根节点中增加URL重写的配置: 可以使用正则表达式
<RewriterConfig>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/(\d{2})\.aspx</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1&month=$2&day=$3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor>
<SendTo><![CDATA[~/ShowBlogContent.aspx?year=$1&month=$2]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d{4})/Default\.aspx</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1</SendTo>
</RewriterRule>
<!-- Rules for Product Lister -->
<RewriterRule>
<LookFor>~/Products/Default\.aspx</LookFor>
<SendTo>~/ListCategories.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Beverages\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Condiments\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Confections\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Dairy\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=4</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/GrainsCereals\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=5</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/MeatPoultry\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=6</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Produce\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=7</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Seafood\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=8</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
3 <httpModules> 增加
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
或者
<httpHandlers> 增加
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
4 完成.
5 其他问题:
回发后真实路径再现:
1、将ActionlessForm.dll添加到项目的bin文件夹
2、在aspx网页的代码中加<%@ Register TagPrefix="RW" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
3、然后将form标签改为RW:Form(注意开始和结束都要改),TagPrefix可以自定义
另外:DOTNET3.5 提供了 System.Web.Routing 命名空间
可以自己实现想要的URL重写.
参考文章:
http://www.cnblogs.com/Ferry/archive/2009/06/19/1506770.html
http://www.blogjava.net/Unmi/archive/2010/06/14/323349.html
从以上2篇文章地址可以看出,其服务器也使用了URL重写方式
1)隐藏真实URL,提高安全性
2)更加友好的URL,好记(看博客园就行知道啦)
3)便于搜素引擎收录
.........
可能的缺点
使用URL重写可能导致:
1)图片路径的问题
2)CSS路径的问题
3)性能问题
.........
先下载DLL包,附带了源码的.
download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi
URLRewriter.dll和ActionlessForm.dll
或者只使用DLL 本人已经上传:http://files.cnblogs.com/yun_shuai/URLRewriter.rar 含有上面2个DLL
使用方法 :WEB项目中添加引用
webconfig中配置:
1 <configSections> 节点中增加:
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"/>
2 <configuration>根节点中增加URL重写的配置: 可以使用正则表达式
<RewriterConfig>
<Rules>
<!-- Rules for Blog Content Displayer -->
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/(\d{2})\.aspx</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1&month=$2&day=$3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d{4})/(\d{2})/Default\.aspx</LookFor>
<SendTo><![CDATA[~/ShowBlogContent.aspx?year=$1&month=$2]]></SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/(\d{4})/Default\.aspx</LookFor>
<SendTo>~/ShowBlogContent.aspx?year=$1</SendTo>
</RewriterRule>
<!-- Rules for Product Lister -->
<RewriterRule>
<LookFor>~/Products/Default\.aspx</LookFor>
<SendTo>~/ListCategories.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Beverages\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Condiments\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Confections\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Dairy\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=4</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/GrainsCereals\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=5</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/MeatPoultry\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=6</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Produce\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=7</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>~/Products/Seafood\.aspx</LookFor>
<SendTo>~/ListProductsByCategory.aspx?CategoryID=8</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
3 <httpModules> 增加
<add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
或者
<httpHandlers> 增加
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
4 完成.
5 其他问题:
回发后真实路径再现:
1、将ActionlessForm.dll添加到项目的bin文件夹
2、在aspx网页的代码中加<%@ Register TagPrefix="RW" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
3、然后将form标签改为RW:Form(注意开始和结束都要改),TagPrefix可以自定义
另外:DOTNET3.5 提供了 System.Web.Routing 命名空间
可以自己实现想要的URL重写.
参考文章:
http://www.cnblogs.com/Ferry/archive/2009/06/19/1506770.html
http://www.blogjava.net/Unmi/archive/2010/06/14/323349.html
从以上2篇文章地址可以看出,其服务器也使用了URL重写方式
- web.config的配置(一)
- web.config的配置
- Web.config 的配置
- web.config的配置(二)
- asp.net 安全认证学习(一)-web.config 配置
- Ajax的Web.config配置
- web.config文件的配置
- web.config的相关配置
- beta2的web.config配置
- web.config的一些配置
- web.config的相关配置
- N2CMS的web.config配置
- NeatUpload的web.config配置
- Sharepoint的web.config配置
- SessionState的配置(web.config)
- WEB.CONFIG的配置记录(积累中)
- ASP.NET的高级配置Web.config和Machine.Config
- 由Duwamish学习web.config的配置
- oracle实用语句
- C# 生成随机数问题
- VC++实现HTTP代理
- 浅谈android的selector背景选择器
- ===《c/c++笔记》===向量容器
- web.config的配置(一)
- 关于Tomcat 不能识别 Eclipse工作区间 Java web 工程
- Eclipse CDT launch failed.Binary not found解决方案
- JS this作用域以及GET传输值过长的问题
- python3.x 对 python2.x 语法变动
- 前线解释多线程《二》
- Android ImageView图片自适应
- c文件操作 (转)
- 利用JDBC访问dept表