global-asax

Why HttpContext.Current.Session is null in Global.asax?

两盒软妹~` 提交于 2019-11-27 03:15:10
问题 I'm using VS2010 and created a simple asp. web forms application, using Development Server to test it. I try to store user data - queried from sql server - in the session, since I don't want to access database in every request. I'm using the 'Application_AuthenticateRequest' and the 'Session_Start' methods. First round: AuthenticateRequest called. The following code ran: public static void Initialize(string login_name, bool force_refresh) { HttpSessionState Session = HttpContext.Current

Difference between Application_Start and Application_OnStart

有些话、适合烂在心里 提交于 2019-11-27 01:28:13
问题 I'm in the process of adding ASP.NET MVC code to a preexisting ASP.NET Webforms project. The various tutorials suggest adding routing to a method called from Application_Start() in Global.asax. My Global.asax already has an Application_OnStart(Object,EventArgs) method with some setup code. If I try to have both Start and OnStart, the OnStart doesn't get called (and the setup fails, causing errors). It looks like I have to choose one or the other. My question is: which one should I be using?

Where is the Global.asax.cs file?

感情迁移 提交于 2019-11-27 01:18:51
问题 I am using VS 2008. I have created a new Asp.net web site project from File->New->Website->Asp.net Website. Now I want to add the Global.asax as well as the .cs file to the project. So I Right click on the project ->Add New Item->Global Application Class. Then I clicked on the add button. The Global.asax file got added with the content as under <%@ Application Language="C#" %> <script runat="server"%> void Application_Start(object sender, EventArgs e) { // Code that runs on application

Is it possible to debug Global.asax?

て烟熏妆下的殇ゞ 提交于 2019-11-27 00:16:53
问题 I can't debug global.asax file! I have some codes in Application_Start() method but when I set a break point in the method, it is ignored! Is this normal? 回答1: Maybe you should try: stopping development server in taskbar switching the configuration from release to debug 回答2: A simple way to break in Application_Start() is to use the System.Diagnostics.Debugger class. You can force the application to break by inserting System.Diagnostics.Debugger.Break() where you would like the debugger to

global.asax Application_Error not firing

被刻印的时光 ゝ 提交于 2019-11-26 23:13:57
问题 My global.asax seems not to be firing. I have: void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs Server.Transfer("~/ExceptionFormView.aspx"); } In my web.config, I don't have anything like CustomErrors. As I want everything to be handled by Global.asax and transferred to ExceptionFormView.aspx. It works fine locally, but not when we deploy to servers. Any thoughts? Do I need PrecompiledApp.config? 回答1: If you do not have a customErrors

ASP.NET MVC doesn't call global.asax' EndRequest

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 23:08:04
问题 I am trying to perform some actions at the end of every request. I changed the Application_Start() that is generated when created new project to make a test: protected void Application_Start() { EndRequest += (s, e) => { Console.Write("fghfgh"); }; RegisterRoutes(RouteTable.Routes); } The lambda won't get called. Any ideas why? edit: I see that they are doing similar thing in SharpArch [http://code.google.com/p/sharp-architecture/] and it does work there... And no, I don't want to use an

When to use Application_Start vs Init in Global.asax?

蹲街弑〆低调 提交于 2019-11-26 19:01:21
问题 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

ASP.NET MVC Url Route supporting (dot)

倾然丶 夕夏残阳落幕 提交于 2019-11-26 18:44:49
I hope that you can help me with the below problem. I am using ASP.NET MVC 3 on IIS7 and would like my application to support username's with dots. Example: http://localhost/john.lee This is how my Global.asax looks like: ( http://localhost/ {username}) routes.MapRoute( "UserList", "{username}", new { controller = "Home", action = "ListAll" } ); The applications works when I access other pages such as http://localhost/john.lee/details etc. But the main user page doesn't work, I would like the app to work like Facebook where http://www.facebook.com/john.lee is supported. I used below code and

Application_End global.asax

ε祈祈猫儿з 提交于 2019-11-26 17:49:22
问题 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? 回答1: 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

Global.asax not firing for Release build

瘦欲@ 提交于 2019-11-26 17:17:40
问题 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