Where is global.asax.cs in Visual Studio 2010

32,714

Solution 1

That's because you created a Web Site instead of a Web Application. I would recommend you using a precomipled Web Application model but if you need to use a Web Site you could do the following:

~/Global.asax:

<%@ Application CodeFile="Global.asax.cs" Inherits="AppName.MyApplication" Language="C#" %>

~/Global.asax.cs:

namespace AppName
{
    public partial class MyApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
        }
    }
}

Now reopen your site in VS.

Solution 2

Yes @Darin's Answer is right, the cs/vb file can be seen in the Web Application but in the website you can't have a separate cs/vb file.

Global.asax doesn't have a cs file, but you can write code....

<script runat="server">

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

</script>

Solution 3

Actually in VS 2010 standard website, a code behind file is not present by design for Global.asax. So what to do? You have to use inline code model like this.

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

<%@ Import Namespace="System.Web.Routing" %>

<script Language="C#" RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
    }

    void Application_End(object sender, EventArgs e)
    {
    }

    void Application_Error(object sender, EventArgs e)
    {
    }

    void Session_Start(object sender, EventArgs e)
    {
    }

    void Session_End(object sender, EventArgs e)
    {
    }
</script>

Solution 4

Press Ctrl+Shift+A and add global application class from the list

Share:
32,714
naveen
Author by

naveen

ASP.NET Consultant, JavaScript Enthusiast, Lover, Husband, Father. In other words, yet another coder... Email: Click here

Updated on March 09, 2020

Comments

  • naveen
    naveen over 4 years

    I don't have a Global Application class code-behind any more inside my installed templates. All I have is Global.asax. I find more comfortable working with Global.asax.cs.

    1. Why am I not seeing it anymore?
    2. How to re-create Global.asax.cs?