asp.net 3.5中的Url重写
我正在开发一个asp.net 3.5应用程序。我需要重写url。我当前的url是 这个url将非常长,用户不频繁。所以我需要将这个url减少到下面的url 在这里,像EventID和status这样的查询字符串是动态生成的。所以我们需要动态地传递这些查询字符串。所以我们不能硬编码这些值 我们尝试在web.config.中使用标记,但它没有用。因为在这里我们无法在web.config中传递动态值 所以,请告诉我,如何做到这一点。有任何应用程序在互联网上请给我的网址asp.net 3.5中的Url重写,asp.net,Asp.net,我正在开发一个asp.net 3.5应用程序。我需要重写url。我当前的url是 这个url将非常长,用户不频繁。所以我需要将这个url减少到下面的url 在这里,像EventID和status这样的查询字符串是动态生成的。所以我们需要动态地传递这些查询字符串。所以我们不能硬编码这些值 我们尝试在web.config.中使用标记,但它没有用。因为在这里我们无法在web.config中传递动态值 所以,请告诉我,如何做到这一点。有任何应用程序在互联网上请给我的网址 提前谢谢。我不知道这是否有用
提前谢谢。我不知道这是否有用,但也许将来会有人使用它。我们使用以下代码重写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);
}
}
} `