【发布时间】:2012-07-24 06:31:27
【问题描述】:
我正在开发一个具有以下属性的项目:
Asp.net
C#
.Net Framework 4
IIS 7
在其中,我使用Application_BeginRequest 像这样手动重写:
void Application_BeginRequest(object sendet, EventArgs e)
{
bool IsUploading = System.Configuration.ConfigurationManager.AppSettings["IsUloading"] == "1";
if (Request.Headers["X-Requested-With"] == "XMLHttpRequest")
{
return;
}
string Path = Request.RawUrl;
string QueryString = "";
if (Request.QueryString.Count != 0)
{
string[] u = Path.Split(new char[] { '?' });
Path = u[0];
QueryString = u[1];
}
string url = "";
if (Path.EndsWith(".css") || Path.EndsWith(".js") || Path.EndsWith(".png") || Path.EndsWith(".jpg") || Path.EndsWith(".jpeg") || Path.EndsWith(".bmp") || Path.EndsWith(".htm") || Path.EndsWith(".png") || Path.EndsWith(".gif") || Path.EndsWith(".fla") || Path.EndsWith(".swf") || Path.EndsWith(".axd") || Path.EndsWith(".xml") || Path.EndsWith(".ashx"))
return;
if (!Path.EndsWith("/"))
Path += "/";
IEnumerator<string> Part = Path.Split(new char[] { '/' }).AsEnumerable<string>().GetEnumerator();
if (Part.MoveNext() && Part.MoveNext())
{
if (Part.Current == "")
url = "Default.aspx";
else if (Part.Current.ToLower() == "public")
{
if (Part.MoveNext() && Part.Current.ToLower() == "install")
url = "Public/Install.aspx";
else
url = "Public/PageNotFound.aspx";
}
else
url = "Public/PageNotFound.aspx";
}
else
url = "Public/PageNotFound.aspx";
if (url.Contains("?"))
Context.RewritePath("~/" + url + "&" + QueryString);
else
Context.RewritePath("~/" + url + "?" + QueryString);
}
现在当尝试浏览页面 localhost:97 时,浏览器开始打开 Default.aspx 但是如果我尝试打开 localhost:97/Public/Install 浏览器会给我这个错误:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
哪里出错了?!!!
UPDATE1 :当我尝试浏览 localhost:97/Public/Install 时,VS 不会在我在此事件中放置的断点处停止。我认为我的请求在 IIS 中被拒绝了。
UPDATE2:我知道我的代码是 100% 正确的,因为我们正在使用 TFS 服务器,而另一台计算机没有任何问题,只是我的计算机遇到了这个问题。
对不起,我的英语不好。我是新的。更详细的评论我。
【问题讨论】:
-
首先放入一些日志/调试语句,这样您就可以看到代码对您的路径做了什么。由于您正在手动处理路径并且还可能进行重写,因此最终请求将是什么会变得非常混乱。
-
@mellamokb ,我试了一下,设置了一些断点,但是我的请求在 IIS 中停止了,VS 没有对断点起作用,你到底是什么意思?!
标签: asp.net iis-7 url-rewriting