url重写的问题??
我是按这种方式来写的。。。
protected void Application_BeginRequest(Object sender, EventArgs e)
{
string strRawUrl = HttpContext.Current.Request.RawUrl;
string strNewUrl;
if (Regex.IsMatch(strRawUrl, @"default.aspx", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"default.aspx", @"showforum.aspx\?fld=1");
HttpContext.Current.RewritePath( strNewUrl );
}
else if (Regex.IsMatch(strRawUrl, @"(\d+).aspx", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"(\d+).aspx", @"View.aspx\?ID=$1");
HttpContext.Current.RewritePath(strNewUrl);
//HttpContext.Current.Response.Redirect( strNewUrl );
}
else if (Regex.IsMatch(strRawUrl, @"View.aspx\?ID=(\d+)", RegexOptions.IgnoreCase))
{
strNewUrl = Regex.Replace(strRawUrl, @"View.aspx\?ID=(\d+)", @"$1.aspx");
HttpContext.Current.Response.Redirect( strNewUrl );
}
}
但现在跳过去是提示我404错误,请问还需要做哪些处理呢?该如何做。
问题点数:100、回复次数:6Top
1 楼qugui(阿贵)回复于 2005-11-05 12:24:21 得分 10
你跳过去后的URL路径是什么?
直接输该URL路径有文件没有?Top
2 楼xiahouwen(武眉博<活靶子.NET>)回复于 2005-11-05 12:27:27 得分 40
eg:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path.ToLower();
string ArticleID;
Regex regex = new Regex(@"/Files/(\d+)/(\d+)/(\d+).aspx", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
MatchCollection matches = regex.Matches(oldpath);
if (matches.Count > 0)
{
ArticleID = matches[0].Groups[3].ToString();
incoming.RewritePath(Request.ApplicationPath + "/ShowArticle.aspx?ID=" + ArticleID);
}
}Top
3 楼baogong(包公)回复于 2005-11-06 00:02:15 得分 0
xiahouwen(活靶子.NET) :
我用了你的方法,但还是出现如下的问题,找不阿相应的文件。
但事实上我的文件是存在的。
我用的是iis6.0
不知道是否需要在iis中做相应的设置信息。
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
to:qugui(阿贵)
直接输入该地址是可以正常访问的。Top
4 楼shiro(比卡丘)回复于 2005-11-13 01:19:20 得分 20
iis中aspx文件配置里“确认文件是否存在”的勾要打掉的Top
5 楼btut2004(养鱼炒股)回复于 2005-11-29 13:37:41 得分 20
用asp.net来处理并不是最好的方式.Top
6 楼xiahouwen(武眉博<活靶子.NET>)回复于 2005-11-29 13:46:53 得分 10
看看iis的isapi筛选器内是否 勾了确认文件存在 有救去掉Top





