global-asax

What is the difference between Server.MapPath and HostingEnvironment.MapPath?

Hi, I wanted to ask what if there is any difference between Server.MapPath and HostingEnvironment.MapPath? Does Server.MapPath have any advantages over HostingEnvironment.MapPath? My original problem was mapping file path on a server when context is not present and I cannot pass Server variable from Global.asax to my method. I used Hos...

How to limit users to Login?

I have a scenario in which I have to restrict the users for login as per following details: Whenever 500th user try to login My web-site there would be a message "User login exceeds, please login later!". Only 499 users can login at a time, 500th user is the Admin. Also need to show online users in admin page-view. So, how to calculate...

Log4Net, ThreadContext, and Global.asax

I am working on a Log4Net configuration that will log all unhandled exceptions. I need certain properties, based on user, to be added to each log entry. I have set this up successfully in the following manner in my Application_Error event. Here is my complete global.asax Imports log4net Imports log4net.Config Public Class Global...

<machineKey decryptionKey="AutoGenerate"... being ignored by IIS. Won't invalidate previous session's cookies.

(See question below for more context): Are there any situations in which <machineKey validationKey="AutoGenerate,IsolateApps" decryptionKey="AutoGenerate,IsolateApps"/> in web.config would fail to AutoGenerate a new machineKey on App Pool recycle? This is the behavior I'm seeing... I'm using standard ASP.NET FormsAut...

How do I detect if a request is a callback in the Global.asax?

I need to find a way to detect if a request is a callback when the Application_BeginRequest method is called.     Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)        Dim _isCallBack As Boolean = False          [Code to set _isCallBack is True or False Here]          If Not _isCallBack Then           ... So...

Check if IsCallback on Application_BeginRequest

I have a web application (.NET 3.5) that has this code in Global.asax: Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) LinkLoader() PathRewriter() PathAppender() End Sub I want all those functions inside to get called except for when it's an AJAX call back. So, ideally I would have it changed to:...

PreRequestHandlerExecute event not fired for REST calls

I'm creating my nhibernate session in the PreRequestHandlerExecute event handler of the HttpApplication class. It works fine for MVC, however, when in WCF (REST) the event is never fired. Is there a way to make it happen or any other better idea to set the session both in MVC and WCF/Rest? Thanks in advance, André Carlucci ...

Global.asax Application_Error doesn't work with Integrated Mode

Application_Error doesn't work with Integrated Mode but does work with Class Mode. I would to transfer request to error page using both Integrated Mode and Class Mode. Can this be done or I have to use HTTP module in order to support both modes? protected void Application_Error(object sender, EventArgs e) { if (Context != null && Co...

Global.asax's Application_BeginRequest is not being hit

I have a Website that is using .NET 1.1 app pool and then I also have a Virtual Directory within that website that is .NET 3.5. This Virtual Directory's contents are built with Visual Studio 2008 as a separate project. When testing, everything works fine and all Global.asax events are hit and the app goes through the execution pipe lin...

ASP.NET :Access Session variable in global.asax

I have an ASP.NET application and in the golbal.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 e) { //get reference to the source of the exception chain Exception ex = Server....

Should you use the method Application_Error in your global.asax in ASP.NET MVC?

I know that in ASP.NET people typically put a protected method called "Application_Error" in their global.asax file inorder to handle say, logging of exceptions. My question is, is this an ASP.NET only thing, or does it work equally well in ASP.NET MVC? Is it an ASP.NET MVC best practice or not? ...

ASP.NET 2.0: Problem in Httpcontext.current.session.add()

Hi, Can anybody help me to find out solution of following problem. In ASP.NET website: at Application_OnPostAuthenticate() event, whatever code i write is executed for every request. therefore due to this customidentity object, countryid and weatherid is called everytime for each request (call for database for value). It effect respon...

Exceptions, Global.asax, and the eventlog.

I would like to log unhandled exceptions from the global.asax to the Application eventlog. However, I've noticed that IIS is already logging these unhandled exceptions as warnings. Is there a way to suppress these messages since I'm planning on logging them myself or do you think it’s reasonable to have both entries there (the event lo...

ASP.NET 2.0 : Best Practice for writing Error Page

In asp.net 2.0 web site, what is the best way of writing Error page. I have seen following section at following location: Web.Config <customErrors mode="RemoteOnly" defaultRedirect="~/Pages/Common/DefaultRedirectErrorPage.aspx"> Global.asax void Application_Error(object sender, EventArgs e) { } I am not getting how to use ...

Can I map new routes to the RouteCollection outside Global.asax?

I'd like to occasionally map new routes to the RouteCollection during program execution long after the Global.asax RegisterRoutes() method had first executed. How can I do this? ...

Web client software factory CreateNewAttribute property not working in global.asax

We are using the following code in a code behind page [CreateNew] public AdminController Controller { get; set; } and the following code within the controller class [ServiceDependency] public IAdminService Adminervice { get; set; } this works fine for a normal aspx page. I would like to audit a Session starting event in my applica...

Question about the use and scope of global.asax (for file cleanup after application ends)

Hey guys, I apologize for this basic question, but for the life of me I can't seem to find an answer. I previously asked a question here about how to dynamically store temporary images and handle their cleanup on a web server's file system. (using C# in .NET 3.5) It was suggested that I use a global.asax file to handle this. I just...

ASP.Net use of documents

I have a problem in my asp.net application. The users can access a document, but only one user can access one document at the same time. When a user gets a document, a flag in the db is updated for the document, indicating that the document is in use. When the user finnishes working with the document, this flag is updated again to indica...

Profile_OnMigrateAnonymous event firing multiple times

We have an HTTPModule whose sole purpose is to do "url rewriting". By definition of an HTTPModule, ALL browser requests (html, css, javascript, images, etc) go through the event handlers of this class. During the signin process, we are catching the moment when the user switches from "anonymous" to "signed-in" user in the Global.asax's P...

Application_BeginRequest for static *.JS files in ASP.NET in IIS6?

I'm trying to do something seemingly simple: ensure that Application_BeginRequest is called for every static *.JS URL sent to my IIS6 website, whether or not the underlying file exists. What's a good way to do this on IIS6 & ASP.NET 3.5, ideally without causing all static files to go through ASP.NET-- only the .JS URLs? If you're cur...