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

URL重写,怎么让传过去的id转换成用户名后,在重写URL(顶者有分)
现在我在做一个博客,想做URL映射,让地址显示为http://localhost/blog/userName
但我现在真实地址是这样的
http://localhost/blog/index.aspx?id=***
我要怎么做才能把   这个id号转换成用户名,然后在映射成我的要URL?userName在数据库中!



------解决方案--------------------
哈哈,沙发
------解决方案--------------------
如果已经会Url重写了,直接查数据库再重写就可以了. 或者不转换,在index.aspx中查一下用户名也可以.
------解决方案--------------------
友情帮顶
------解决方案--------------------
UP下
------解决方案--------------------
学习+顶顶
------解决方案--------------------
关注中````求正解`````
------解决方案--------------------
搜索一下利用httpmodule进行重写. HttpContext.Current.RewritePath( "aaa.aspx?id= "+sId);
------解决方案--------------------
http://www.ssxz.com/iuhxq/index.html
------解决方案--------------------
顶一个,学习
------解决方案--------------------
已经有username了还需要id吗,直接用正则取到username,然后sql就好了
------解决方案--------------------
学习
学习
UP
------解决方案--------------------
JF
------解决方案--------------------
恩,主要就是自己写个httpmodule
拦截请求,解析request 的url
然后重新转向就可以了~~
------解决方案--------------------
学习~
------解决方案--------------------
顶。。
------解决方案--------------------
先顶
------解决方案--------------------
学习
------解决方案--------------------
这里有一种最常用的方法
http://localhost/blog/index.aspx?id=***
http://localhost/blog/index_***.html

------解决方案--------------------
up
------解决方案--------------------
ID号都有想要什么得不到?
------解决方案--------------------
net2.0框价中有
System.Net.HttpListener
System.Net.HttpListenerRequest
两个类
在web.config <httpModules> 中添加
<httpModules>
<add name= "HttpListenerModule " type= "portal.HttpListenerModule "/>
</httpModules>


namespace portal
{
/// <summary>
/// HttpListenerModule的摘要说明

/// </summary>
public class HttpListenerModule:IHttpModule
{
// IHttpModule::Init
public void Init(HttpApplication app)
{
// 注册管道事件
app.AcquireRequestState +=
new EventHandler(OnAcquireRequestState);
}

// IHttpModule::Dispose
public void Dispose() {}

// 确定是否正在处理 F5 或后退/前进操作
private void OnAcquireRequestState(object sender, EventArgs e) {
// 访问 HTTP 上下文
HttpListener listener = new HttpListener();