Questions tagged [global-asax]

A special file in the ASP.NET framework, it provides a simplified interface to create hooks into system events in the life cycle of a web application and web pages in that application.

A special file in the ASP.NET framework, it provides a simplified interface to create hooks into system events in the life cycle of a web application and web pages in that application.

Most often used to define resources which need to be globally defined for use by all web pages and services.

1047 questions
134
votes
12 answers

Multiple HttpPost method in Web API controller

I am starting to use MVC4 Web API project, I have controller with multiple HttpPost methods. The Controller looks like the following: Controller public class VTRoutingController : ApiController { [HttpPost] public MyResult…
Habib
  • 219,104
  • 29
  • 407
  • 436
130
votes
4 answers

How can I use Server.MapPath() from global.asax?

I need to use Server.MapPath() to combine some files path that I store in the web.config. However, since Server.MapPath() relies on the current HttpContext (I think), I am unable to do this. When trying to use the method, even though its…
John B
  • 20,062
  • 35
  • 120
  • 170
111
votes
34 answers

"Could not load type [Namespace].Global" causing me grief

In my .Net 2.0 Asp.net WebForms app, I have my Global.asax containing the following code: <%@ Application CodeBehind="Global.asax.cs" Inherits="MyNamespace.Global" Language="C#" %> However when I build I get an error stating- Could not load type…
gkdm
  • 2,375
  • 4
  • 21
  • 27
81
votes
2 answers

When to use Application_Start vs Init in Global.asax?

I am wondering under what circumstances I should be putting application initialisation code in Application_Start() vs Init() in my Global.asax file? The distinction between the two doesn't seem very obvious to me, other than Application_start gets…
roryf
  • 29,592
  • 16
  • 81
  • 103
52
votes
11 answers

Is it possible to debug Global.asax?

I can't debug global.asax file! I have some codes in Application_Start() method but when I set a break point in the method, it is ignored! Is this normal?
Mehdi
  • 5,435
  • 6
  • 37
  • 57
48
votes
2 answers

Where is the Global.asax.cs file?

I am using VS 2008. I have created a new Asp.net web site project from File->New->Website->Asp.net Website. Now I want to add the Global.asax as well as the .cs file to the project. So I Right click on the project ->Add New Item->Global Application…
apurva
  • 603
  • 2
  • 6
  • 7
45
votes
3 answers

Application_End global.asax

Can anybody tell me when Application_End is triggered in a lifecycle of an application? When all sessions are ended, will Application_End be triggered automatically? + Are there any other reasons why Application_End could be triggered?
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
45
votes
3 answers

Difference between Application_Start and Application_OnStart

I'm in the process of adding ASP.NET MVC code to a preexisting ASP.NET Webforms project. The various tutorials suggest adding routing to a method called from Application_Start() in Global.asax. My Global.asax already has an…
Craig Walker
  • 49,871
  • 54
  • 152
  • 212
44
votes
2 answers

how do you wire up Application_BeginRequest() in asp.net-mvc

I see in global.asax.cs from an ASP.NET MVC project protected void Application_BeginRequest() { } but when I try to add this to my project, I don't see what is calling this method. I see that the base System.Web.HttpApplication has this event…
leora
  • 188,729
  • 360
  • 878
  • 1,366
42
votes
3 answers

Set session variable in Application_BeginRequest

I'm using ASP.NET MVC and I need to set a session variable at Application_BeginRequest. The problem is that at this point the object HttpContext.Current.Session is always null. protected void Application_BeginRequest(Object sender, EventArgs e) { …
Daniel Peñalba
  • 30,507
  • 32
  • 137
  • 219
39
votes
5 answers

ASP.NET MVC Url Route supporting (dot)

I hope that you can help me with the below problem. I am using ASP.NET MVC 3 on IIS7 and would like my application to support username's with dots. Example: http://localhost/john.lee This is how my Global.asax looks like:…
Cindro
  • 1,055
  • 4
  • 12
  • 23
36
votes
23 answers

Parser Error Message: Could not load type 'sometype'

I am experiencing an error that I am unable to resolve for some time now. I was wondering if someone can help identify the cause of this error? I am completely new to asp / asax. After some research, I think that the error I am getting is due to the…
AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231
34
votes
2 answers

what is the global.asax Application_Start equivalent when using WAS in IIS7

I'd like to use the netTcpBinding for my WCF application which is currently hosted in IIS7, which means configuring it to use WAS instead. This is fairly straight forward however, my application previously made use of the Application_Start event in…
Mike Tours
  • 772
  • 2
  • 6
  • 13
22
votes
2 answers

How to catch HttpRequestValidationException in production

I have this piece of code to handle the HttpRequestValidationException in my global.asax.cs file. protected void Application_Error(object sender, EventArgs e) { var context = HttpContext.Current; var exception =…
bruno
  • 1,830
  • 2
  • 22
  • 36
20
votes
7 answers

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. Why am I not seeing it anymore? How to re-create Global.asax.cs?
naveen
  • 53,448
  • 46
  • 161
  • 251
1
2 3
69 70