global-asax

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

安稳与你 提交于 2019-11-28 09:50:25
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.Session; object o = Session == null ? null : Session["EMPLOYEE_DATA"]; if (force_refresh || o == null || o

Get same instance of a component registered with Autofac as InstancePerLifetimeScope in Global.asax methods as is injected into a controllers?

这一生的挚爱 提交于 2019-11-28 09:41:21
问题 I have a situation where I need to manually instantiate some objects in Application_BeginRequest that are dependent on some of the same components that I've registered with Autofac. I'd like to use the same instances of components that I've registered with Autofac with InstancePerLifetimeScope for injection into my MVC and WebAPI controllers. My config for both MVC and Web API works as expected, and an example of a component registration looks like so: builder.Register(c => new MyDbContext())

Difference between Application_Start and Application_OnStart

瘦欲@ 提交于 2019-11-28 06:44:51
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? What is the difference between them? Are they called at different times? (Note: at the time of this

Where is the Global.asax.cs file?

白昼怎懂夜的黑 提交于 2019-11-28 06:11:01
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 startup } void Application_End(object sender, EventArgs e) { // Code that runs on application shutdown } void

Application_Error does not fire?

眉间皱痕 提交于 2019-11-28 04:07:28
问题 In Webform1.aspx.cs: protected void Page_Load(object sender, EventArgs e) { throw new Exception("test exception"); } In the Global.asax.cs: protected void Application_Error(object sender, EventArgs e) { // Code that runs when an unhandled error occurs if (Server.GetLastError() is HttpUnhandledException) Server.Transfer("ErrUnknown.aspx"); } But the Application_Error event handler never gets called. Instead I get a runtime error page. What do I have to do have Application_Error being called

Is it possible to debug Global.asax?

旧时模样 提交于 2019-11-28 04:05:17
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? Maybe you should try: stopping development server in taskbar switching the configuration from release to debug Patrick Lee Scott 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 break. void Application_Start(object sender, EventArgs e) { System.Diagnostics.Debugger.Break();

IIS Recycle Global.asax

℡╲_俬逩灬. 提交于 2019-11-28 00:05:21
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 splattne 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.com/jmstall/archive/2006/11/26/process-exit-event.aspx Process recycle will kill the process if it

global.asax Application_Error not firing

一个人想着一个人 提交于 2019-11-27 22:49:33
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? Jesse Webb If you do not have a customErrors section in your Web.config, it is the same as having the section with mode="RemoteOnly" . This

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

假装没事ソ 提交于 2019-11-27 22:14:01
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 HttpModule. edit2: The only workaround I found is to use Application_EndRequest in conjuction with a

what alternatives are there to using global.asax?

梦想与她 提交于 2019-11-27 21:27:30
问题 I am using my own custom authentication with IIS, and I want the server on every page load (no matter what type of file) to first check the Application variable to see if the user is authenticated and authorized to see the site. In global.asax this could be: void Application_Start(Object Sender, EventArgs e) { if(Application["username"] == null) { Response.redirect("login.aspx"); } } The problem is that this site has multiple sub-roots. That is, http://example.com/site1 is a completely