首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

用 C# .net 如何实现伪静态

2011-12-23 
用 C# .net 怎么实现伪静态我打算实现这样的地址伪地址http://company.xxx.com/guangxi/nanning/541200或

用 C# .net 怎么实现伪静态
我打算实现这样的地址

伪地址
http://company.xxx.com/guangxi/nanning/541200
或者
http://company.xxx.com/guangxi/nanning/541200/

真是地址
http://www.xxx.com/company/company.aspx?adr1=guangxi&adr2=nanning&adr3=541200

解释
guangxi   是省名
nanning   是市名称
541200     是数据库的ID值

怎么实现这个伪静态   带二级域名的

[解决办法]
用httpmodule

在BeginRequest事件里 获取Request.RawURL 通过正则表达式匹配后RewritePath到实际的地址

可以参考微软的UrlWriter组件。 有源码的
[解决办法]
.net 2.0可以直接在global.asax了写

protected void Application_BeginRequest(Object sender, EventArgs e)
{

string oldurl = HttpContext.Current.Request.RawUrl;
//判断,按规则转成http://www.xxx.com/company/company.aspx?adr1=guangxi&adr2=nanning&adr3=541200

//比如,这里只是例子,更多规则自己定义即可
if(oldurl.EndsWith( "541200 "))
HttpContext.Current.RewritePath( "/company/company.aspx?adr1=guangxi&adr2=nanning&adr3=541200 ");
}
[解决办法]
1.webconfig配置下重写规则
2.用URLREWRITE.DLL
3.IIS配置
[解决办法]
请看看这篇文章,“asp.net URL重写(URLRewriter)”
http://www.code-123.com/html/2008715112705589432.html

热点排行