您的位置:首页 > 编程语言 > ASP

使用ASP.NET实现Friendly URL的最简单方法

2007-05-10 19:23 1031 查看
这大概是最简单的方法。只要2步。

在Global.asax中加入:


void Application_BeginRequest(Object sender, EventArgs e)




...{


string strCurrentPath;


string strBasePath;


string strCustomPath;


strCurrentPath = Request.AppRelativeCurrentExecutionFilePath.Substring(2).ToLower();


strBasePath = Request.ApplicationPath;




if (strCurrentPath != string.Empty && !strCurrentPath.Contains("."))




...{


strCustomPath = strBasePath + "/Load.aspx?page=" + strCurrentPath;


// rewrite the URL


Context.RewritePath(strCustomPath);


}


else if (strCurrentPath == string.Empty)


Context.RewritePath(strBasePath + "/Default.aspx"); // by default


else




...{


Context.RewritePath(strBasePath + "/" + strCurrentPath);


}


}

IIS Application Configuration 设置中的 Application Mapping加入Extension: * Executable Path:和aps.net一样。这样做可以防止IIS来报错404。所有的事情都由asp.net来解决。接下来就可以慢慢编写Load.aspx的内容罗。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐