没有Application_BeginRequest事件?
为什么我的全局应用程序类Global.asax里面没有Application_BeginRequest事件,怎么弄出来,,如果手动加应该没有效果的吧? --------------------编程问答-------------------- 没有,自己增加一个呗在ASP.NET中实现和利用URL重写 Global.asax文件的Application_BeginRequest()方法
void Application_BeginRequest(object sender, EventArgs e)
{
string path = Request.Url.ToString();
if (Regex.IsMatch(path, "/URLRewriting/OldUrl.aspx", RegexOptions.IgnoreCase))
{
Context.RewritePath("/URLRewriting/NewUrl.aspx");
}
else if (Regex.IsMatch(path, "/URLRewriting/UserAccount/(.+).aspx", RegexOptions.IgnoreCase))
{
string idString = path.Substring(path.LastIndexOf('/') + 1, path.Length - path.LastIndexOf('/') - 6);
Context.RewritePath("/URLRewriting/UserAccount.aspx?id=" + idString);
}
}
通过使用Request.Url属性来获得输入的URL路径,然后通过正则表达式来应用网站URL重写规则,匹配到期望的输入网址后,将它们重写成你希望转向的网址。 --------------------编程问答--------------------
void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.UserHostAddress == "127.0.0.1")
{
HttpContext.Current.Response.Write("已被屏蔽");
HttpContext.Current.Response.End();
}
}
我自己写了一个,但是调试的时候设置断点,这段代码根本不会跳进去运行 --------------------编程问答-------------------- --------------------编程问答--------------------
void Application_Start(object sender, EventArgs e)
{
// 在应用程序启动时运行的代码
this.BeginRequest += new EventHandler(Global_BeginRequest);
}
void Global_BeginRequest(object sender, EventArgs e)
{
//throw new NotImplementedException();
} --------------------编程问答--------------------
貌似不行额。。 --------------------编程问答-------------------- Global.asax根本就没有执行吧 --------------------编程问答--------------------
执行了。。我还在代码里写了一旦执行就创建一个TXT文件的。。每次都执行的 --------------------编程问答-------------------- 开发环境版本多少,3.5的环境下面上面的代码都可以测试通过的 --------------------编程问答--------------------
framework 4 --------------------编程问答-------------------- 有些版本在Global.asax不会自动生成事件列表,手动输入可以的
补充:.NET技术 , ASP.NET