ASP.NET中的Global.asax事件 [英] Global.asax events in ASP.NET

查看:55
本文介绍了ASP.NET中的Global.asax事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,

我在ASP.NET应用程序中有些困惑。



1)是否必须添加global.asax在Asp.net网站上的文件?如果不是强制性的,那么在那种情况下应用程序级别事件(开始和结束)是否会触发?如果触发了我们获得实现的地方或调用这些方法。



Hi Experts,
I have some confusion in ASP.NET application.

1)Is it mandatory to add global.asax file in Asp.net website?If is not mandatory then in that case application level event(start and end) fire or not?If fire then where we got the implemention or invoke these methods.

void Application_Start(object sender, EventArgs e)
       {
           // Code that runs on application startup

       }

       void Application_End(object sender, EventArgs e)
       {
           //  Code that runs on application shutdown

       }





2)假设您在web.conf中启用了会话ig并抛出你没有使用session的应用程序,所以在这种情况下这些global.asax事件是否会触发?





2)Suppose you have enable session in web.config and threw out application you have not used session any where so in that case these global.asax event fire or not?

void Session_Start(object sender, EventArgs e)
     {
         // Code that runs when a new session is started

     }

     void Session_End(object sender, EventArgs e)
     {

     }





3)假设你没有添加global.asax然后我们去实现或调用这些会话事件(启动和申请。





谢谢

Dinesh Sharma



我尝试了什么:



我试图在没有global.asax的asp.net中执行网站。但是找不到应用程序和会话级事件的实现。



3)Suppose you have not add global.asax then where we have go the implement or invoke these session event (start and end) in application.


Thanks
Dinesh Sharma

What I have tried:

I have tried to execute website in asp.net without global.asax. But not find the implement ion of application and session level events.

推荐答案

不一定要包含它。但是如果你需要在app start和其他事件上做一些工作,你必须包含它。事件总是在适当的时候触发,如果你不改变它们就会使用默认实现。



要改变它们,你必须拥有全局.asax。



答案:

1)不,不是强制性的。是的,事件开始了。你没有调用它们,它们是事件。

2)ASP.NET应用程序中总有一个会话。您不必使用它,但默认事件仍将触发(您不必对它们执行任何操作,只需忽略它们)。

3)如果您不包含全局.asax,你没有实现这些事件。同样,这些是事件,它们在应用程序生命周期中的适当时间触发,你不会调用它们。



也就是说,你可以创建等价的类到具有相同功能的global.asax,但为什么要这么麻烦?包含文件,覆盖您需要覆盖的事件并乘坐日落。
It is not mandatory to include it. But if you need to do some work on app start and other events, you have to include it. The events trigger always at appropriate times, it is just that they use default implementation if you don't change them.

And to change them, you have to have global.asax.

So answers:
1) No, not mandatory. Yes, events fire. You don't invoke them, they are events.
2) There is always a session in ASP.NET app. You don't have to use it, but default events will still fire (and you don't have to do anything with them, just ignore them).
3) If you didn't include global.asax, you don't get to implement the events. Again, these are events, they fire at appropriate times in the application life cycle, you don't invoke them.

That said, you could probably create the class equivalent to global.asax with same functionality, but why bother? Include the file, override the events you need to override and ride into the sunset.


这篇关于ASP.NET中的Global.asax事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆