asp.net – Global.asax PostAuthenticateRequest事件绑定是如何
如何使用Global.asax的PostAuthenticateRequest事件?我正在关注
this tutorial,它提到我必须使用PostAuthenticateRequest事件.当我添加Global.asax事件时,它创建了两个文件,标记和代码隐藏文件.这是代码隐藏文件的内容
using System; using System.Web; using System.Web.Security; using System.Web.SessionState; namespace authentication { public class Global : System.Web.HttpApplication { protected void Application_Start(object sender,EventArgs e) { } protected void Session_Start(object sender,EventArgs e) { } protected void Application_BeginRequest(object sender,EventArgs e) { } protected void Application_AuthenticateRequest(object sender,EventArgs e) { } protected void Application_Error(object sender,EventArgs e) { } protected void Session_End(object sender,EventArgs e) { } protected void Application_End(object sender,EventArgs e) { } } } 现在我打字的时候 protected void Application_OnPostAuthenticateRequest(object sender,EventArgs e) 它被成功调用.现在我想知道PostAuthenticateRequest是如何绑定到这个Application_OnPostAuthenticateRequest方法的?如何将方法更改为其他方法? 解决方法
Magic …,一种叫做Auto Event Wireup的机制,与你可以编写的原因相同
Page_Load(object sender,EventArgs e) { } 在您的代码隐藏中,该方法将在页面加载时自动调用. MSDN description for
当AutoEventWireup为true时,处理程序会根据其名称和签名在运行时自动绑定到事件.对于每个事件,ASP.NET都会搜索根据模式Page_eventname()命名的方法,例如Page_Load()或Page_Init(). ASP.NET首先查找具有典型事件处理程序签名的重载(即,它指定Object和EventArgs参数).如果找不到具有此签名的事件处理程序,ASP.NET将查找没有参数的重载.更多详情,请见this answer. 如果你想明确地这样做,你会写下面的内容 public override void Init() { this.PostAuthenticateRequest += new EventHandler(MyOnPostAuthenticateRequestHandler); base.Init(); } private void MyOnPostAuthenticateRequestHandler(object sender,EventArgs e) { } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-mvc – mvc.net如何在迭代列表时使用强类型助手
- asp.net-mvc – Linq离开外连接不起作用
- asp.net – 分析器错误消息:无法生成代码.抛出了类型’Sys
- 使用C#实现网站用户登录
- asp.net – 如何在SQL数据库中创建和存储用户定义的自定义字
- asp.net-mvc – 如何设置TextBox的空字符串而不是null的默认
- asp.net – 在MVC5中使用java脚本代码 – 放在哪里
- 实现不要在asp.net mvc中跟踪
- asp.net-mvc – SQL CE 4.0还是SQL Express?果园对吗?
- asp.net-mvc – 如何在MVC中完全分离视图和模型