Where is global.asax.cs in Visual Studio 2010 Where is global.asax.cs in Visual Studio 2010 asp.net asp.net

Where is global.asax.cs in Visual Studio 2010


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.


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>


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>