日期:2014-05-18  浏览次数:20517 次

用 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