【发布时间】:2017-12-13 10:36:20
【问题描述】:
我正在运行的网站包含 Global.asax 文件和 App_global.asax.compiled 也 App_global.asax.dll 但现在我想编辑或添加一些现有的 url 重写代码。 但是当我在 global.asax 文件中编写代码时,它没有被占用。
经过大量谷歌搜索和搜索后,我知道我必须在更改完成后再次编译该全局文件。但我不能这样做,因为 websi## Heading ##te 是实时的,我没有解决方案。
Global.asax 中的现有代码:
protected void Application_BeginRequest(object sender, EventArgs e)
{
HttpContext myContext=HttpContext.Current;
Regex rewrite_regex = new Regex(@"(.+)\/((.+)\.*)", RegexOptions.IgnoreCase);
try
{
// 'see if we need to rewrite the URL
Match match_rewrite =rewrite_regex.Match(myContext.Request.Path.ToString());
string str = match_rewrite.Groups[2].Captures[0].ToString();
string root = match_rewrite.Groups[0].Captures[0].ToString();
if (Regex.Match(root, "/News/", RegexOptions.IgnoreCase).Success)
{
myContext.RewritePath("~/Default2.aspx?nid="+str);
}
else if (Regex.Match(root, "/Search/", RegexOptions.IgnoreCase).Success)
{
myContext.RewritePath("~/Default.aspx?text=" + str);
}
else if (Regex.Match(root, "/Find/", RegexOptions.IgnoreCase).Success)
{
myContext.RewritePath("~/Default.aspx?text=" + str);
}
任何帮助都会非常有用。
【问题讨论】:
标签: asp.net .net global-asax