global-asax

When to use Application_Start vs Init in Global.asax?

筅森魡賤 提交于 2019-11-27 17:34:26
I am wondering under what circumstances I should be putting application initialisation code in Application_Start() vs Init() in my Global.asax file? The distinction between the two doesn't seem very obvious to me, other than Application_start gets called first, then Init() . Why would I use one over the other? Does it really make a difference? What changes in the application state between the two events? So far the only real pointer I can find is that IHttpModule only has an Init() method, so if what I'm doing may at some point be better suited to implement IHttpModule I should use the Init()

.NET Application_BeginRequest - How to get User reference?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-27 16:00:46
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? Jim Schubert You don't have access to the User object because the request hasn't yet been authenticated. Try using Application_AuthenticateRequest instead. Here is an explanation of all Global.asax events: https://web.archive.org/web/1/http://articles.techrepublic%2ecom%2ecom/5100-10878_11-5771721.html And the MSDN walkthrough of the application

Global.asax not firing for Release build

时光毁灭记忆、已成空白 提交于 2019-11-27 15:45:27
One of our applications has a mechanism for emailing our Helpdesk automatically should it encounter a certain level of exception. One particular exception, a NullReferenceException, is causing a few problem and I believe it is caused by IIS recycling and losing the session. To prove this I want to log when the application is started/stoped/recycled and have added some code to the global.asax file to do this. Running on Debug mode the log messages are written out and all seems well. The problem comes when I switch to Release build, which triggers a Web Deployment Project to build to a folder

Set session variable in Application_BeginRequest

半世苍凉 提交于 2019-11-27 14:21:29
问题 I'm using ASP.NET MVC and I need to set a session variable at Application_BeginRequest . The problem is that at this point the object HttpContext.Current.Session is always null . protected void Application_BeginRequest(Object sender, EventArgs e) { if (HttpContext.Current.Session != null) { //this code is never executed, current session is always null HttpContext.Current.Session.Add("__MySessionVariable", new object()); } } 回答1: Try AcquireRequestState in Global.asax. Session is available in

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

放肆的年华 提交于 2019-11-27 12:20:52
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 access has been removed in IIS7), however I would still like to hook into the start or init methods? Does an equivalent exist when hosting an application in WAS as apposed to IIS7? Using classic mode is not an option(again I'm not interested in the httpcontext and

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

ぃ、小莉子 提交于 2019-11-27 11:43:42
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 ErrorController to display custom errors. This code is taken from here : protected void Application_Error(object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Clear(); HttpException httpEx = ex as HttpException; RouteData routeData = new RouteData(); routeData.Values.Add("controller", "Error"); if (httpEx == null) { routeData

Application_End global.asax

白昼怎懂夜的黑 提交于 2019-11-27 09:11:06
Can anybody tell me when Application_End is triggered in a lifecycle of an application? When all sessions are ended, will Application_End be triggered automatically? + Are there any other reasons why Application_End could be triggered? The application_end event primarily fires when the IIS pool is recycled or the application itself is unloaded. One other thing to note, that a change to a dependent file (say web.config) will cause the application to reload itself, which will in cause the application_end event to fire while it is closing itself off. To note, the only instance I found of the

Parser Error Message: Could not load type 'sometype'

谁说我不能喝 提交于 2019-11-27 05:49:25
问题 I am experiencing an error that I am unable to resolve for some time now. I was wondering if someone can help identify the cause of this error? I am completely new to asp / asax. After some research, I think that the error I am getting is due to the web application trying to use outdated code. I was thinking to rebuild the c# file using Visual Studio and/or the entire project. However, I am completely new to C# and asp, and was wondering can give me some suggestions if this may fix the

IIS Recycle Global.asax

↘锁芯ラ 提交于 2019-11-27 04:42:29
问题 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 回答1: So, here is an idea how this could work. Based on my previous answer (attach to AppDomain.CurrentDomain.ProcessExit) and stephbu's comment: This will trap most structured process teardowns e.g. - but I'm not sure that it will trap all tear downs. e.g. http://blogs.msdn

Asp.net System.Web.HttpContext.Current.Session null in global.asax

喜欢而已 提交于 2019-11-27 03:53:15
问题 I have a custom security principal object which I set in the global.asax for the current thread and all is well, no problems normally. However, I'm just adding a dynamic image feature by having a page serve up the image and whenever that dynamic image page is loaded the System.Web.HttpContext.Current.Session is null in global.asax which prevents me from setting the security principal as normal and cascading problems from that point onwards. Normally the Session is null in global.asax only