我正在尝试为我的网站编写SEO友好的URL。为此我在global.asax中编写了以下代码。
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext incoming = HttpContext.Current;
string oldpath = incoming.Request.Path;
string imgId = string.Empty;
// string imgName = string.Empty;
Regex regex = new Regex(@"N/(.+)", RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace);
MatchCollection matches = regex.Matches(oldpath);
if (matches.Count > 0)
{
imgId = matches[0].Groups[1].ToString();
// imgName = matches[0].Groups[2].ToString();
string newPath = String.Concat("~/inner.aspx?Id=", imgId);
incoming.RewritePath(String.Concat("~/inner.aspx?Id=", imgId), false);
}
}
但是当正则表达式匹配时,此代码会进行无限循环。当我在此代码中应用调试器时,它在正则表达式匹配时无限移动。请帮我解决这个问题。