Samiey Mehdi
Samiey Mehdi

Reputation: 9414

How to add global.asax file to ASP.NET MVC4 project?

In my project the Global.asax file is removed. I want add a global.asax file to my projet.
But in Add New Item dialog the Global.asax not exist.

Upvotes: 34

Views: 63280

Answers (3)

Michael Socha
Michael Socha

Reputation: 1798

Just in case you may have missed the item even though it may actually be there for you I'll post this answer.

In Visual Studio 2013

  1. Open Solution Explorer.
  2. Right-click on the project.
  3. Add New Item.
  4. VB or C#
  5. Web.
  6. General.
  7. Global Application Class.

Upvotes: 92

Samiey Mehdi
Samiey Mehdi

Reputation: 9414

  1. Create an empty new project.
  2. Go to that folder and copy the Global.asax file.
  3. Go to your project and in solution explorer paste it on root.
  4. Open Global.asax file and change namespace match to your namespace.
  5. In solution explorer right click on Global.asax and pick View Markup and change inherits match to your namespace.

Upvotes: 14

G. Stoynev
G. Stoynev

Reputation: 7783

Any problem doing this:

  • Create a new empty project and get it from there (drag-and-drop from Windows Explorer to Visual Studio works fine), or
  • Add, say aspx page or any item, then rename accordingly (to get the code behind file, add and rename another item); in this case, they'll obviously be empty.

Upvotes: 0

Related Questions