override Application_Start...

Topics: Web Client Software Factory
May 20, 2007 at 2:57 PM
Hi,

I would like to override or add some code to Application_Start but it is inherited from Microsoft.Practices.CompositeWeb.WebClientApplication. How can I handle this?
Developer
May 21, 2007 at 2:31 PM
Hi,

What you have to do, is create a CustomWebClientApplication and inherits from Microsoft.Practices.CompositeWeb.WebClientApplication. In this new class now you only have to overrides the Application_Start method.

For your convenience here is the class definition:
public class CustomWebClientApplication : WebClientApplication
{
    protected override void Application_Start(object sender, EventArgs e)
    {
        base.Application_Start(sender, e);
        
        // Add your code here
    }
}
Remember to change the Global.asax to use this new class, you have to change this line:
<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>
Please let me know if this helps you,

Ezequiel Jadib
http://staff.southworks.net/blogs/ejadib
May 31, 2007 at 10:20 AM
Hi Ezequiel,

what schould I do if I want perform some logic on the Application_End( http://www.codeplex.com/websf/Thread/View.aspx?ThreadId=10767 ) I can't find this method in the WebClientApplication class.

KR,
Boris
Jun 1, 2007 at 3:26 PM
Boris,

try this create a class as Ezequiel said in your App_code folder for example and then put in the events you want to capture

eg.


public class CustomWebClientApplication : WebClientApplication
{
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
}

protected void Application_End(object sender, EventArgs e)
{
}
}


Hope it helps.

Regards
Jul 19, 2007 at 4:08 PM
Edited Jul 19, 2007 at 4:24 PM
Ezequiel, I added code like you put in your example (seems very straight forward), along with other application events (in particular Application_AuthenticateRequest). Unfortunately my app does not seem to be reading the application events, but I know it is reading the CustomWebClientApplication.cs file as I can set static variables that my app is aware of. Any ides? This is really frustrating me... Thanks for any help given...
Jul 20, 2007 at 12:46 AM
Edited Jul 20, 2007 at 12:46 AM
Where are you adding the event handlers at? Overriding start does not work. Use should use Init()

public override void Init()
{
base.Init();
this.PostAuthenticateRequest += new EventHandler(MyWebApplication_PostAuthenticateRequest);
}

void MyWebApplication_PostAuthenticateRequest(object sender, EventArgs e)
{

}
Jul 21, 2007 at 3:46 PM
stormbringer,

My guess is that you forgot to point to your custom application class in the Global.asax file in your web application.

By default it says this:

<%@ Application Language="C#" Inherits="Microsoft.Practices.CompositeWeb.WebClientApplication" %>

but as Ezequiel mentioned, you need to change it to the name of your custom class:

<%@ Application Language="C#" Inherits="???????" %>

This will then make sure your eventhandlers get called in your custom application class.

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
Aug 1, 2007 at 1:10 PM
Edited Aug 1, 2007 at 9:51 PM
Excellent David, thanks! That indeed was what I was doing.