url重写的问题??

baogong 2005-11-05 12:19:08
我是按这种方式来写的。。。

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错误,请问还需要做哪些处理呢?该如何做。
...全文
239 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
活靶子哥哥 2005-11-29
  • 打赏
  • 举报
回复
看看iis的isapi筛选器内是否 勾了确认文件存在 有救去掉
张海霖 2005-11-29
  • 打赏
  • 举报
回复
用asp.net来处理并不是最好的方式.
比卡丘 2005-11-13
  • 打赏
  • 举报
回复
iis中aspx文件配置里“确认文件是否存在”的勾要打掉的
baogong 2005-11-06
  • 打赏
  • 举报
回复
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(阿贵)
直接输入该地址是可以正常访问的。
活靶子哥哥 2005-11-05
  • 打赏
  • 举报
回复
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);
}
}
qugui 2005-11-05
  • 打赏
  • 举报
回复
你跳过去后的URL路径是什么?
直接输该URL路径有文件没有?

62,073

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧