global-asax

Shared Global.asax & Error.aspx files

I have several ASP.NET websites in a solution along with a common C# code project. Something as follows: Website1 Website2 ... Website(n) Common First off I want to use a Global.asax file to log all unhandled exceptions. I could have one Global.aspx file per website but all the code will be the same and it seems pointless having to k...

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

Hi 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 the global.asax file. I do not require access to the httpContext(which I understand ac...

Server.Transfer("error_404.aspx") in Application_Error returns a blank page

I look for HttpExceptions in the Application_Error sub of my global.asx Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) Dim ex As Exception = HttpContext.Current.Server.GetLastError() If ex IsNot Nothing Then If TypeOf (ex) Is HttpUnhandledException Then If ex.InnerExcept...

How can I utilize or mimic Application OnStart in an HttpModule?

We are trying to remove the global.asax from our many web applications in favor of HttpModules that are in a common code base. This works really well for many application events such as BeginRequest and PostAuthentication, but there is no Application Start event exposed in the HttpModule. I can think of a couple of smelly ways to overc...

Show alert message box from the Global.asax (on Application_Error event)

Normally I just redirect to a custom error page in on the Application_Error event, but I have a specific error for which I'd like to display an alert message while the user is still on the page which triggers the error. How can I make this happen? I'm open to a modalpopup or any other type of error message, I just want to ensure the us...

asp.net profiles not working in global.asax?

I have a class that returns parameters I've set in the profile properties in web.config. It works great on classes, but I cannot seem to make it work under the Global.asax? Here is how I get the parameter: public static string MissingPagePath { get { return HttpContext.Current.Profile.GetPropertyValue("MissingPage").ToString(); } }...

Storing Requested URL in Global.asax without Session State in ASP.NET

I have a complex URL rewriting scheme which breaks the built in Forms Authentication ReturnUrl mechanism. I would like to grab the requested URL for later redirection away from my login.aspx. I can get this URL in Application_BeginRequest via HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath. However, Session state is not a...

Global.asax parser errors when deploying MVC 1 application to remote server.

So we're having some issues deploying an ASP.NET MVC app to a client site. Basically when we try to test the app from localhost, we get the dreaded Global.asax parser error indicating it could not load the application global. Research indicates there are basically 4 possible reasons for this exception we're seeing: The solution hasn'...

Clearing Session in Global Application_Error

Whenever an unhandled exception occurs on our site, I want to: Send a notification email Clear the user's session Send the user to a error page ("Sorry, a problem occurred...") The first and last I've had working for a long time but the second is causing me some issues. My Global.asax.vb includes: Sub Application_Error(ByVal sender...

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

Hello, 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 web.config conditionally (depending on whether the application is deployed (remote) or ...

Cookie add in the Global.asax warning in application log

In my Global.ASAX file i have the following: void Session_End(object sender, EventArgs e) { System.Web.HttpCookie isAccess = new System.Web.HttpCookie("IsAccess"); isAccess.Expires = DateTime.Now.AddDays(-1); isAccess.Value = ""; System.Web.HttpContext.Current.Response.Cookies.Add(isAccess); } So every time this meth...

stripping default.aspx and //www from the url

the code to strip /Default.aspx and //www is not working (as expected): protected void Application_BeginRequest(object sender, EventArgs e) { HttpContext context = HttpContext.Current; string url = context.Request.RawUrl.ToString(); bool doRedirect = false; // remove > default.as...

Fire just once a Thread in Asp.net WebSite Global.asax

I've a legacy application using Asp.Net WebSite (winforms...) and I need run a background thread that collect periodically some files. But this thread must run just one time! My problem start when I put a method in Application_Start: void Application_Start(object sender, EventArgs e) { SetConnection(); SetNHibernate(); SetN...

Move Global.asax to iHttpModule when using ASP.NET MVC

I have successfully created an iHttpModule to replace my Global.asax file in many Web Forms applications. But in looking at the Global.asax file in my MVC application, the methods are totally different. I'm wondering if it is still possible to create this same thing in an MVC app. I know it's not necessary and the Global.asax works ju...

Accessing HttpRequest from Global.asax via a page

I'm trying to get a property (ImpersonatePersonId) from a page in global.asax but get a HttpException saying 'Request is not available in this context'. I've been searching for some documentation on where in the pipeline the request is accessible, but as far as I can see all Microsoft can produce of documentation is one-liners like "P...

Deleting files when user logouts or session end

I'm trying to delete files created by current user when he/she clicks logout button Protected Sub OnLoggingOut(ByVal sender As Object, ByVal e As EventArgs) Handles LoginStatus1.LoggingOut Try Dim folder As String = Server.MapPath("~/uploads/") Dim files As String() = Directory.GetFiles(folder) ...

.NET Application_BeginRequest - How to get User reference?

I'm trying to get a reference to the user object in my Global.asax file's Application_BeginRequest. I'm using the property Context.User but I get a NullReferenceException. Is it possible to get a user object reference in Application_BeginRequest? ...

.NET MVC - Where to check IsInRole() in Global.asax?

In which part of the Global.asax lifecycle can I safely 'use' the User object? I'm using the default forms authentication and noticed the following: Sub Application_BeginRequest() 'Context.User Is Nothing End Sub Sub Application_AuthenticateRequest() 'Context.User Is Nothing End Sub Sub Application_AuthorizeRequest() 'Cont...

.NET MVC Forms authentication - debug IsInRole()?

I'm using Forms authentication on my MVC website. I administrate users and roles using the default ASP.NET Configuration option in Visual Studio. All good so far. I can successfully do Page.User.IsInRole("Moderator") in a View. True is returned as expected. However when calling Context.User.IsInRole("Moderator") inside Global.asax's Ap...

Asp.NET Global.asax - application lifecycle

I am using Visual Studio 2005, and running my application from inside it, directly using its development application server. If I set a breakpoint inside Application_Start and one inside Session_Start, the latter is reached first, and I honestly think it should be the other way around. Any thoughts? ...