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
7
votes
4 answers

Where the methods of Global.asax come from?

When I add Global.asax to the page, five methods (Application_Start,Session_Start,...) are added to the page automatically. But where they come from ? I looked at the application class and its interfaces but I couldnt find them at all. Thanks in…
Barış Velioğlu
  • 5,709
  • 15
  • 59
  • 105
7
votes
2 answers

What's the performance difference between HttpModule and Global.aspx?

I have made a web app where I am using a module which redirects without "www" urls (http://example.com/) to with "www" urls (http://www.example.com/). But as I am on shared hosting server, where I don't have permission to implement a HttpModule,…
djmzfKnm
  • 26,679
  • 70
  • 166
  • 227
7
votes
2 answers

Event handlers can only be bound to HttpApplication events during IHttpModule initialization

I am getting the following error 'Event handlers can only be bound to HttpApplication events during IHttpModule initialization.' at the following code (line in bold or double **) protected void Application_BeginRequest(object sender, EventArgs…
Zohaib
  • 496
  • 7
  • 21
7
votes
3 answers

Confused over global.asax?

I have a class called Global that derives from HttpApplication. Oddly, I see a lot of methods inside Global that look like: void Application_Start(object sender, EventArgs e) { } The code is definitely executing inside this method, so the method is…
maxp
  • 24,209
  • 39
  • 123
  • 201
7
votes
4 answers

IIS Recycle Global.asax

Is it possible to catch an recycle event in the global.asax? I know Application_End will be triggered but is there a way to know that it was triggered by a recycle of the application pool? thx, Lieven Cardoen aka Johlero
Lieven Cardoen
  • 25,140
  • 52
  • 153
  • 244
7
votes
2 answers

Application_BeginRequest not being fired during PUT API Calls on IIS Server

Background I have an MVC Application with a WebAPI component. I'm using jQuery and AJAX to pass and receive data from the WebAPI. I rely on the Application_BeginRequest being fired during each call to perform some mundane task.…
Mark Barciak
  • 71
  • 1
  • 2
7
votes
2 answers

Should I throw out an exception that happen in Application_Error handler in Global.asax?

The unhandled error codes in aspx.cs will be caught by Application_Error handler in global.asax. I have write some codes in Application_Error handler to log such unhandled errors happened in aspx.cs But if the codes of log itself also fails and…
Richard
  • 145
  • 1
  • 9
7
votes
2 answers

What pattern is being done in the Global.asax.cs file in ASP.NET MVC 4?

I have never come across this pattern of code right here. Would anyone care to explain it to me? (Or is there even a pattern here? Is there a reason why this was done like this? What benefits is this giving?) I'm new at general programming, and this…
JCCV
  • 75
  • 1
  • 7
6
votes
2 answers

mvc route actionlink url use name instead of id

I think I already asked this but the solution didn't really made sense. Anyway, I have ActionLinks on my views like this: foreach( var item in Model){ <%: Html.ActionLink(item.Name, "Details", new {id = item.Id}) %> } now, when it goes to my Action…
gdubs
  • 2,724
  • 9
  • 55
  • 102
6
votes
3 answers

Global.asax.cs and Static variable

In a WCF Service, I need to create a variable which should be accessible anytime from anywhere. All methods of my service need to have access to that data and I can load it only once. So I though about using a static variable in the Global.asax.cs.…
Martin
  • 39,309
  • 62
  • 192
  • 278
6
votes
1 answer

Does Application_OnStart in global.asax work with cached pages?

I'd like to implement a counter in global.asax so I can do a giveaway on my site every xxx visits. The question is, if my page is served from the ASP.NET cache, will the counter still update? Thanks in advance
Phil
  • 1,719
  • 6
  • 21
  • 36
6
votes
2 answers

Captcha control not working with url-routing (ASP.NET 4.0 WebForms)

ASP.NET 4.0 C# WebForms I have route.Ignore("{resource}.axd/{*pathInfo}"); in my global.asax for my ajax to work correctly. The control is a "MSCaptcha". It shows the path in sourcefile…
Kasper Skov
  • 1,954
  • 10
  • 32
  • 53
6
votes
2 answers

Application_Error does not fire?

In Webform1.aspx.cs: protected void Page_Load(object sender, EventArgs e) { throw new Exception("test exception"); } In the Global.asax.cs: protected void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled…
ChrisPeeters
  • 153
  • 2
  • 13
6
votes
5 answers

application_start firing unexpectedly asp.net

I am looking at an asp.net application that makes calls to a database within the application start inside global.asax. These calls takes around 3 seconds (depends on SQL cache plan) to run. I have noticed that the application runs slowly when I…
Rippo
  • 22,117
  • 14
  • 78
  • 117
6
votes
3 answers

Asp.Net Global.asax access to the current requested Page object

Is there any way i can access the page object from within the global.asax Application_EndRequest function ? I'm trying to set the text of a label at the end of the request but accessing the page is proving to be more difficult than I thought. here…
John Boker
  • 82,559
  • 17
  • 97
  • 130