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

How to render an asp.net WebForm page from Global.asax?

for one reason or another I'm messing around with a "minimalistic" ASP.Net just for fun. I've disabled a lot of things and am attempting to reimplement things. One thing I can't quite figure out is how to render an ASP.Net page(aspx). This is my…
Earlz
  • 62,085
  • 98
  • 303
  • 499
8
votes
3 answers

Setting Response status code causes unwanted error text at top of custom error page

UPDATE: To ensure that the correct status code is returned to the browser, the error.aspx has this line: <% Response.StatusCode = 500; %> Removing it removes the unwanted text, but I want the correct status code, so I suppose that is the new…
GP24
  • 867
  • 2
  • 13
  • 28
8
votes
2 answers

Find out in Global.Asax - Application_Start if ASP.NET application running locally

HttpContext.Current.Request.IsLocal is not available in Global.Asax/Application_Start (Request is not available in the context). How else could I safely determine if my ASP.NET MVC application is started locally or not? This is to rewrite my…
Alex
  • 75,813
  • 86
  • 255
  • 348
8
votes
4 answers

Application_Start() event in global.asax

Hai guys, My website has thousands of users... I have implemented a background task of sending mails to every user once a day ... I followed this link to do this... http://www.codeproject.com/KB/aspnet/ASPNETService.aspx My question is will…
ACP
  • 34,682
  • 100
  • 231
  • 371
8
votes
1 answer

How can I handle errors in Global.asax Application_Start?

In the interest of always showing a "friendly" error page to users when they visit a site I have a catch-all at the in the Global.asax page, the majority of errors are handled by filters which seems to be the preferred method. For the most part,…
DJG
  • 205
  • 4
  • 8
8
votes
2 answers

Can we unit test global.asax in asp.net?

I am doing unit testing. I have no idea that how to unit test global.asax in asp.net. Is global.asax in asp.net come under unit test coverage ? Also there is application installer class which contain system varibles. Should i test them ?
Ninad More
  • 333
  • 5
  • 11
8
votes
3 answers

HTTPModules and Global.asax -- ASP.NET Page Life cycle

I have read the beautiful article about Asp.Net Page life Cycle http://www.codeproject.com/Articles/73728/ASP-NET-Application-and-Page-Life-Cycle. My understanding is the request passes through MODULE(BeginRequest,authentica,author,prehandler...)…
Peru
  • 2,871
  • 5
  • 37
  • 66
8
votes
3 answers

Handling exceptions in global.asax ASP.NET MVC

I have code which is catching all exceptions in Global.asax protected void Application_Error(object sender, EventArgs e) { System.Web.HttpContext context = HttpContext.Current; System.Exception exc =…
Irakli Lekishvili
  • 33,492
  • 33
  • 111
  • 169
8
votes
1 answer

Why can't I add my custom model binder in my global.asax folder?

I see examples all over the net of people setting up their custom model binders like this: // global.asax protected void Application_Start() { ModelBinders.Binders.Add(typeof(YourModel), new YourBinder()); } But when I try that, it doesn't…
Michael Haren
  • 105,752
  • 40
  • 168
  • 205
8
votes
3 answers

ASP.NET: Access Session variable in global.asax

I have an ASP.NET application and in the Global.asax ' Application Error Event, I am calling a method to trace/log the error. I want to use the session variable content here. I used the below code void Application_Error(object sender, EventArgs…
Shyju
  • 214,206
  • 104
  • 411
  • 497
7
votes
1 answer

Auto-Start application / global.asax / wcf service when IIS7 starts automatically

Thank you for your time :) I'm sorry if this has been asked before, I just really need clarification. Environment: server 2008 R2 64bit Basically what im attempting to do is create an autonomous application that will load even if the server reboots.…
Anthem127
  • 169
  • 2
  • 10
7
votes
4 answers

How do I log unhandled exceptions in ASP.NET MVC?

Here's what I'm trying to do in my Global.asax.vb: Public Class MvcApplication Inherits System.Web.HttpApplication Shared Sub RegisterRoutes(ByVal routes As RouteCollection) routes.IgnoreRoute("{resource}.axd/{*pathInfo}") …
Zack Peterson
  • 56,055
  • 78
  • 209
  • 280
7
votes
1 answer

What is a proper way to validate HTTP requests and return specific HTTP responses in Global.asax?

I'm trying to validate an HTTP request received by a service. I want to check if all required headers are present etc. If not, I'd like to throw an exception, that would, in some place, set a proper response code and status line of the response. I…
Piotr Zierhoffer
  • 5,005
  • 1
  • 38
  • 59
7
votes
3 answers

Check for a static file during Application_BeginRequest?

I have a Global.asx file that needs to do custom authentication, auditing and profiling stuff. This is needed because it supports a SAML based SSO system and needs to override the normal .Net authentication (which doesn't support either SAML or…
Keith
  • 150,284
  • 78
  • 298
  • 434