Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is global.asax.cs in Visual Studio 2010

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?
like image 857
naveen Avatar asked May 19 '11 08:05

naveen


People also ask

Where is global asax CS located?

The Global. asax, also known as the ASP.NET application file, is located in the root directory of an ASP.NET application. This file contains code that is executed in response to application-level and session-level events raised by ASP.NET or by HTTP modules.

How do I add global asax Cs to my website?

How to add global. asax file: Select Website >>Add New Item (or Project >> Add New Item if you're using the Visual Studio web project model) and choose the Global Application Class template. After you have added the global.

What is global asax Cs in MVC?

The Global. asax file is a special file that contains event handlers for ASP.NET application lifecycle events. The route table is created during the Application Start event. The file in Listing 1 contains the default Global. asax file for an ASP.NET MVC application.


2 Answers

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.

like image 175
Darin Dimitrov Avatar answered Oct 22 '22 20:10

Darin Dimitrov


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>
like image 42
Muhammad Akhtar Avatar answered Oct 22 '22 20:10

Muhammad Akhtar