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
14
votes
8 answers

How do I access properties from global.asax in some other page's code behind

Imagine I have a property defined in global.asax. public List Roles { get { ... } set { ... } } I want to use the value in another page. how to I refer to it?
minty
  • 22,235
  • 40
  • 89
  • 106
14
votes
2 answers

ASP.NET MVC app custom error pages not displaying in shared hosting environment

I'm having an issue with custom errors on an ASP.NET MVC app I've deployed on my shared host. I've created an ErrorController and added the following code to Global.asax to catch unhandled exceptions, log them, and then transfer control to the…
Bryan
  • 2,870
  • 24
  • 39
  • 44
14
votes
1 answer

Response.Redirect not working in Global.asax

I have created an error page to show a general message for all unhandled exceptions. This is the code in Global.asax HttpContext ctx = HttpContext.Current; string e404_PAGE = ctx.Request.AppRelativeCurrentExecutionFilePath.ToString(); …
user2062994
13
votes
7 answers

"HttpContext.Current.Session" vs Global.asax "this.Session"

Recently, while working on some code for an ASP.NET project at work. We needed a tracking util to take basic metrics on user activity (page hit count etc) we would track them in Session, then save the data to DB via Session_End in Global.asax. I…
Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
13
votes
3 answers

C# ASP.NET: how to access cache when no HttpContext.Current is available (is null)?

During Application_End() in Global.aspx, HttpContext.Current is null. I still want to be able to access cache - it's in memory, so want to see if I can reference it somehow to save bits to disk. Question - is there a way to reference cache in memory…
Carl J.
  • 343
  • 1
  • 3
  • 8
13
votes
9 answers

log4net with ASP.NET 3.5 problems

I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the first time I've tried to use log4net, I feel like I'm missing a piece of the puzzle. My project references the log4net assembly, and as far as I can tell, it is being…
Rob
  • 25,984
  • 32
  • 109
  • 155
13
votes
2 answers

Session State Not Available In This Context - In Global.asax

I am getting a 'session state not available in this context' error. The error is nested in the sender parameter of a number of methods within the Global.asax…
Jay
  • 740
  • 4
  • 8
  • 19
12
votes
4 answers

Global.asax event that has access to session state

I'm trying to access the session state in my global.asax for every request (page, documents, PDF, etc.). I know i can't do that in Application_BeginRequest, and i thought i could in Application_AcquireRequestState, but it won't works, which is…
Shadowxvii
  • 1,080
  • 2
  • 12
  • 31
12
votes
1 answer

Securing website assemblies with new code security model

I'm currently on a project where we are creating a MVC site. The site needs to use code access security, due to the fact that third party dll's needs to be plugged in, to provide custom functionality. Now we don't want these assemblies to have full…
12
votes
7 answers

global.asax works on local computer but not after i publish to server

How can I get my global.asax file to publish to our ftp site? I have added a global.asax file to my project (using asp.net with c# from vs2010) which works great on my local machine. Then when I publish to our ftp site. Then copy from the ftp folder…
Letseatlunch
  • 2,432
  • 7
  • 28
  • 33
11
votes
4 answers

Access current domain name on Application_Start

Normally to access the current domain name e.g where the site is hosted I do something like string rURL = HttpContext.Current.Request.Url.ToString().ToLower(); But HttpContext is not avaible on Application_Start only from…
TheAlbear
  • 5,507
  • 8
  • 51
  • 84
11
votes
2 answers

Unhandled Exceptions with Global.asax

I am emailing unhandled exception details from global.asax. How can I get the path and/or filename of the aspx file or assembly file where an exception was not handled. This info was showing up in the exception's stack trace when I was developing &…
Ronnie Overby
  • 45,287
  • 73
  • 267
  • 346
11
votes
2 answers

Why does Session_Start in Global.asax.cs cause performance problems?

When I create an empty Session_Start handler in Global.asax.cs it causes a significant hit when rendering pages to the browser. How to reproduce: Create an empty ASP.NET MVC 3 web application (I am using MVC 3 RC2). Then add a Home controller with…
Mike
  • 7,500
  • 8
  • 44
  • 62
11
votes
2 answers

Method invocation is skipped in C#?

I have this simple code : void Application_BeginRequest(object sender, EventArgs e) { Trace.Write("Exception Handling", "......"); } However re-sharper scream (no-error only suggest) about : Method invocation is skipped.…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
11
votes
2 answers

How to avoid passing slow Application_Start times to the end users in ASP.NET

I have quite a slow Application_Start due to having a lot of IoC stuff happen at start up. The problem I'm trying to solve is, how do I avoid passing that start up time to the end user? Assumptions My apps are hosted on AppHarbor so I have no access…
andy
  • 8,775
  • 13
  • 77
  • 122
1 2
3
69 70