views:

511

answers:

3

Hello everyone,

I am developing an HttpModule and using Global.asax. I have developed a class which derives from HttpApplication, but Application_Start method of my class never executes (I create a file at the beginning of Application_Start but the file never creates, and it is why I think Application_Start never executes). I am using VSTS2008 + C# + .Net 3.5.

Any ideas what is wrong and how to debug? I want to confirm I should copy the Global.asax into the root directory of my web site virtual directory, correct? Should I configure anything in web.config to let the HttpModule run?

thanks in advance, George

+1  A: 

Did you add your module to the httpModules section in your web.config? See: http://msdn.microsoft.com/en-us/library/ms227673.aspx

BStruthers
Thanks, I am developing Global.asax, is it a HttpModule?
George2
Actually I only used Application_Start, Application_End and Application_Error in global.asax, is it an httpmodule? I am confused because I think Class derives from IHttpModule is http module and needs explictly register into web.config, and if I just use Global.asax, no need to register explicitly in web.config and it will be automatically used? Any comments?
George2
+1  A: 

you do need to add an entry into web.config http://msdn.microsoft.com/en-us/library/9b9dh535.aspx

alex
Thanks, I am developing Global.asax, is it a HttpModule?
George2
Actually I only used Application_Start, Application_End and Application_Error in global.asax, is it an httpmodule? I am confused because I think Class derives from IHttpModule is http module and needs explictly register into web.config, and if I just use Global.asax, no need to register explicitly in web.config and it will be automatically used? Any comments?
George2
+2  A: 

Application_Start executes only once when an application starts first time. Do you have restarted your application?

Yes, Global.asax must be in the root directory.

You must add your new ASP.NET module into web.config <httpModules> section.

Tadas
Yes, 1. I restart the application pool. Does it mean I restart my application? 2. "You must add your new ASP.NET module into web.config <httpModules> section." -- can you show me a sample please? Actually I only used Application_Start, Application_End and Application_Error in global.asax, is it an httpmodule? I am confused because I think Class derives from IHttpModule is http module and needs explictly register into web.config, and if I just use Global.asax, no need to register explicitly in web.config and it will be automatically used? Any comments?
George2
1. After you restarted AppPool your app stopped. Now when when your app will receive first request Application_Start (should) execute.2. How to register new module - the link from alex answer. Global.asax - this is "the instance of your application", it's not a ASP.NET module. Here you can handle 'global' application events.
Tadas
Thanks Tadas, 1. so if I am using Global.asax, then no need to register any modules into web.config? 2. I find if I send request to ashx file for the same web application, Application_Start of Global.asax is never executed. Is that true? Any ideas?
George2
If you are developing a asp.net module why you are creating a class that derives from HttpApplication? Could you show your code?
Tadas