Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Browse by Tags · View All
SQL Server 119
#SQLServer 88
Oracle 70
#SQL SERVER 35
BRH 31
SQL Server 2012 29
denali 23
#TSQL 19
TSQL 19
C# 15

Archive · View All
October 2011 31
November 2011 30
September 2011 30
August 2011 18
December 2011 15
July 2011 13
June 2011 8
May 2012 4
April 2012 3
January 2010 3

Adding the Global.asax.cs file in Asp.net Web site

Jun 9 2011 3:37AM by Niladri Biswas   

If we use Asp.net Web Application (File -> New-> Project-> Asp.net Web Application) , we can add Global.asax as well as Global.asax.cs file.

However, if we use Asp.net Web site (File->New->Website->Asp.net Website), it is not the case. By default we will have Global.asax file only and not the Global.asax.cs file.

The structure of the Global.asax file is as under


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

<script runat="server">

    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

    }
        
    void Application_Error(object sender, EventArgs e) 
    { 
        // Code that runs when an unhandled error occurs

    }

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

    }

    void Session_End(object sender, EventArgs e) 
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.

    }       
</script>

So how can we add a Global.asax.cs file for a Asp.net Web site project? Let us observer the same in the below steps

Step 1:

Right click App_Code -> Add New Item -> Class -> Rename it as Global.cs . Then click on the Add button.

Step 2:

In the Global.cs file that got created, decorate it by inheriting the class from System.Web.HttpApplication

So the Global.asax.cs file will now look like

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

public class Global : System.Web.HttpApplication 
{
	public Global()
	{
		//
		// TODO: Add constructor logic here
		//
	}
}

We can add some events to it as under


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// 
/// Summary description for Global
/// 
public class Global : System.Web.HttpApplication 
{
	public Global()
	{
		//
		// TODO: Add constructor logic here
		//
	}

     protected void Application_Start(object sender, EventArgs e)
     {

     }

     protected void Session_Start(object sender, EventArgs e)
    {

    }

    protected void Session_End(object sender, EventArgs e)
    {

    }

    protected void Application_End(object sender, EventArgs e)
    {

    } 
}

Step 3:

Now, from the Global.asax file, remove the entire script code and change the


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

to


<%@ Application Language="C#" CodeBehind="~/App_Code/Global.asax.cs" Inherits="Global" %>

That’s it. Now run the application and it will work

Hope this helps atleast for the newbies. Happy coding.

Tags: ASP.NET, BRH, Global.asax,


Niladri Biswas
7 · 21% · 6720
0
Liked
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • I do not see what is the need of adding this. We can directly start working on the global.asax. And this article may lead to misconception that website do not contain global.cs file. But it has Global.asax with server side coding, so we can directly start working there. It follows inpage technique.

    commented on Sep 24 2011 12:14PM
    Hima
    31 · 6% · 1776

Your Comment


Sign Up or Login to post a comment.

    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]