我不知道這是否會有所幫助,但也許有人在未來可以使用它。我們使用以下代碼進行URL重寫:
private void ProcessRequestedURL()
{
string paths = "|site|pages|from|navigation|go|here|"; // Follow the format of |xxx|xxx|...|
string[] parts = Request.Path.Split('/');
if (paths.ToLower().Contains("|" + parts[1].ToLower() + "|") && !parts[2].Contains(".") && !parts[2].ToLower().Contains("presentations"))
{
string page = null;
string directory = null;
string request = null;
string rewriteUrl = null;
directory = parts[1];
page = parts[2];
request = Regex.Replace(Request.Path, string.Concat("/", directory, "/", page, "/"), "", RegexOptions.IgnoreCase);
rewriteUrl = "/";
if (parts[1].ToLower() != "vgm") // special case. "vgm" means site root.
{
rewriteUrl += string.Concat(directory, "/");
}
if (File.Exists(string.Concat(Request.PhysicalApplicationPath, rewriteUrl, page, ".aspx")))
{
rewriteUrl += string.Concat("", page, ".aspx?req=", request);
Context.RewritePath(rewriteUrl);
}
else
{
rewriteUrl = string.Concat("/404Error.aspx?aspxerrorpath=", page, ".aspx&req=", request);
Context.Response.StatusCode = 404;
Context.Response.Redirect(rewriteUrl);
}
}
} `
來源
2012-07-09 20:43:32
jlg