Events in Global.asax are not firing - asp.net

In my ASP.Net application, I can't get the events in Global.asax to fire on my machine. For instance, Session_Start will not fire.
The same Global.asax works fine on other development machines in my office.
I have tried:
Both the ASP.Net Development Server
and my local IIS
Rebooting the machine
Removing and recreating the file from
the project (including deleting it
from disk)
All machines are configured the with
the same level of software (VS2008
SP1, .Net 3.5, XP)
This is driving me crazy, any help out there?
EDIT: Since the application works on other machines, I don't think it is directly related to the contents of Global.asax. For some reason, my machine does not process the files. I have done a repair of VS 2008 and .Net 2.0. Any other ideas?
EDIT: The application running on all three machines is being pulled directly from source control. It is definitely something specific to the one machine.
Thanks,
Pat

Application level events only need proper naming to work. Is your codebehind class being designated in your Global.asax file?
<%# Application Inherits="YourNamespace.YourApplicationClass" Language="C#" %>

This is a long shot but I have been bitten by this before. When you created your Global.asax.cs file did you make sure to include a basic Global.asax file in your project?
Also make sure that the inherits property in that Global.asax is pointing to your custom class (namespace and all) in your Global.asax.cs file.
I had this problem once and it was because I totally forgot to make the Global.asax file and hook it up to my class. I had just copied the Global.asax.cs from another project that did something similar.

becuase project is compiled first and then you have add or modify or changed location of global.asax.vb.
Solution :- Just remove debug folder. Clean project and then rebuild whole project.
Regards,
Mihir

As I write here, in my case, I was publish my site in production and I miss copy to server App_global.asax.compiled file. For this reason was not fire the Events inside Global.asax.
Hope anyelse help this tips, I lost 8 hours seeking.

If you have fiddled with ASP.NET then maybe try reinstalling it.

Related

ASP.NET and Source Code Appearing

I have an older ASP.NET web-application using framework 2.0 based on Dot Net Nuke. The web-application used to compile and run but recently it compiles fine but instead of the application running in the browser, source code appears. What could be causing this type of behavior? Thank you.
Sounds to me like IIS is treating your .aspx files as static content.
Open IIS admin and make sure the .aspx extensions are mapped to PageHandlerFactory. Make sure the pages exist in an application (and not just a virtual directory). Easiest thing to do is open up IIS in a known good environment and compare the setup.
Also, make sure you have run aspnet_regiis with the appropriate .NET version.

Issues with precompiled website and server control (parser error)

I am deploying our system to a brand new server that was previously untouched and having serious issues with .NET (the error points to server controls but i think this is a symptom rather than the problem)
Basically the VB6 code seems to work correctly but when moving over to the .NET I keep getting a parser error when loading the server control.
Like this
Im quite sure that the server control isnt the issue and there isnt an issue with the compiled code. I have copied the code over from a working deployment on another server.
The code is organised as a WebSite rather than Web Application
The control is referenced at the top of the aspx page like so
<%# Register Namespace="CustomWebControls" TagPrefix="Fastrack" %>
CustomWebControls is in the App_Code folder and is compiled into App_Code.dll
I think there is some issue with windows or IIS config stopping the reading of the compiled app_code.dll file. I have checked user permissions and allowed all to access i have manually copied over the dlls to the asp temp folders.
Other things tried
reinstalled IIS
reinstalled .NET
checked web and machine.config files against known working ones
checked iis installed components are correct
I'm completely out of ideas with this one and I'm not sure where to go next.
The stack trace disappears off deep into System.Web.UI and doesn't hint at any issues with our code at all (doesn't even seem its getting as far as loading it)
Platform
Windows 2008 R2
IIS 7
.NET 4
ASP.Net webforms
If anyone has any suggestions or would like some more info from me let me know.
After much ripping out of hair and sleepless nights the anser was a missing precompiledApp.config file!
The hardest ones often have the simplest answers!

ASP.NET isn't automatically rebuilding

If you create an ASP.NET Web Site project and run it, you get a blank page. If you go into the default CodeBehind file, add into the Page_Load method throw new Exception();, save the file, and refresh it in the browser (without rebuilding), the server automatically rebuilds the project and the page will error.
I have a project that I am working on now where refreshing the page does not cause the project to be rebuilt (the new aspx files are used but the old DLLs are used with them). What causes this, and how do I correct it?
Is this new project a web application project by any chance? I believe you have to actually build that before changes will be seen.
Web Application Project is a separate type of project that requires all code behind to be build. The resulting dll is build under the bin folder. The code behind files are not used in execution, and is the preffered way of doing it if you don't want to expose your code at the installed web server, and to be sure execution is faster (never compiling in runtime).
When you creatied it as "ASP.NET Web Site", it is NOT a "Web Application Project".
Only code which is in App_Code will be automatically recompiled when it changes. If your code lives anywhere else, then it's part of the pre-built DLL you get when you hit "compile".
You are using the Website model. The pages will be compiled when you access them. Class Library projects in the same solution will not. Hence why you see this behaviour.
By default, the ASPX, code behind and App_Code source files get compiled. If you have a seperate project in the solution (a BLL or DAL perhaps), these will not be updated by simply refreshing the browser.
So to correct it you could do a proper build in Visual Studio, or you could move the class files you want to change into App_Code. Personally I'd stick with the former (actually I don't ever use the Website option- always Web application project).
OK. Have you got 'Edit and Continue' enabled?
MSDN

Why are the Global.asax events not firing in my ASP .NET website?

I've been developing an ASP .NET 3.5 web application against Cassini, the built-in web development server, rather than against IIS.
In my Global.asax file, in the Application_Start event handler, I have some code which logs the fact that the website has started up. This all works fine with Cassini.
Since deploying the site to a virtual directory on a test server using IIS6, I am finding there are no log entries being written, and so I'm concluding that the Application_Start handler is not firing.
I then tried removing the virtual directory and running the site directly out of the root of the website on the test server, but it didn't make any difference - still no log entry for application start.
I know these events should fire irrespective of my deployment environment, has anyone got any ideas what is going wrong here?
I had a similar problem and I was wrestling with it for several days.
The initial problem was something else - cookies not being set in Application's EndRequest handler.
Finally I somehow managed to realize, that the problem actually was that the event is not being fired at all.
It took some time to find that out, because all was working fine on my machine.
But on the production server - quiet as a tomb.
I am only writing this, because I really hope to save from troubles at least one person.
The real reason for the problem was a missing global.asax file on the production server.
The global.asax file was present on my computer, because the development environment is located there.
I had prepared a deployment bat file, which coppies files from the development folder, removes the unnecessary ones and makes a package.
Well - the global.asax file was marked for deletion in that script.
After starting to deploy it all the problems went away.
I hope I helped.
If you make a request to your app does the "Application_Start" fire then? I don't believe it will be started until the first request is made.
How are you logging? Is it possible that your logging component is not correctly set up? For a quick test try throwing an exception inside Application_Start and that will tell you quickly whether or not the event is being raised.
In your deployed enviroment, what is the thing you're calling? The reason I ask is because if you're calling a WCF based web service (ending in .svc), then Applicaiton_Start will not fire as the call to WCF isn't going through the ASP.NET pipeline. This wouldn't necessarily rear it's head w/ Cassini.
You may be getting a runtime exception that is occurring before your .NET code even gets a chance to run. If you look under the Event Viewer's Application logs, you may see some warnings or errors that will clue you in to what is happening.
When you develop in Cassini you are running the application under the user's account- probably administrator. Once you've deployed to IIS, you are (hopefully) running under a lower privilidge account.
This lack of appropriate permissions is probably the reason why your application is not working correctly- I would check the security settings to write to the log (presumably you are writing to a log file?).
1) iisreset /stop
2) push the published code to iis virtual directory's physical folder.
3) iisreset /start
4) make web request
Still not sure after this. the do a Thread.Sleep(60000); and attach with remote debugger to the process w3wp.exe imagename.
There may be more than one process of that name but this one is managed code also doesn't hurt to attach to multiple. Set the break point after the sleep. After the one minute sleep step through.
I thought I had a similar problem, working on some old projects, I was under the impression that the global.asax was not running because the code would first go into building my authentication controller which would fail because of class not registered (that part happens in the global.asax).
Turned out it was due to a config item. When I moved the AuthenticationModule declaration into handler section in web config, it worked fine with IIS express.
Basically, because of a config item, another piece of code was being executed before global.asax, making me believe that it would not be called.
We tried a lot of things.
global.asax works on local computer but not after i publish to server
Global.asax is not publishing and event are not firing in Global.asax
Global.asax not firing for Release build
Mystery of Global.asax in ASP.NET MVC application
We also tried putting the below files in root and bin directories.
App_global.asax.dll and App_global.asax.compiled files
PrecompiledApp.config
None of it worked!
We had to put raw Global.asax instead of pre-compiled dll, in order to fire the global events, for our asp .net 2.0 website.
Hope this helps someone! Cheers! Happy coding! :D
My fix was an odd one. On my development machine I am using localhost and I changed the port number it used - and then it worked.
also in IIS Manager turn on Dot Net debugging. It's under "Compilation"
If a required dll is missing from the bin directory (for example there could be a 3rd party dll which has been used in your latest build, but accidently excluded from deployment), then the Application_Start will not fire.
My issue was resolved by adding the below compiled files in the bin folder.
App_global.asax.compiled
App_global.asax.dll

Could not load type 'XXX.Global'

Migrating a project from ASP.NET 1.1 to ASP.NET 2.0 and I keep hitting this error.
I don't actually need Global because I am not adding anything to it, but after I remove it I get more errors.
The reason I encounter this issue is because I change the build configuration. When I set a web project to x86, it changes the output path to bin\x86\Debug. However, the output path should be bin and the web server won't find the binaries because of this.
The solution thus is to change the output path of the website back to bin after you change the build configuration.
There are a few things you can try with this, seems to happen alot and the solution varies for everyone it seems.
If you are still using the IIS virtual directory make sure its pointed to the correct directory and also check the ASP.NET version it is set to, make sure it is set to ASP.NET 2.0.
Clear out your bin/debug/obj all of them. Do a Clean solution and then a Build Solution.
Check your project file in a text editor and make sure where its looking for the global file is correct, sometimes it doesnt change the directory.
Remove the global from the solution and add it back after saving and closing. make sure all the script tags in the ASPX file point to the correct one after.
You can try running the Convert to Web Application tool, that redoes all of the code and project files.
IIS Express is using the wrong root directory (see answer in VS 2012 launching app based on wrong path)
Make sure you close VS after you try them.
Those are some things I know to try. Hope one of them works for you.
I've found that it happens when the Global.asax.(vb|cs) wasn't converted to a partial class properly.
Quickest solution is to surround the class name 'Global' with [square brackets] like so (in VB.Net):
Public Class [Global]
Inherits System.Web.HttpApplication
...
Deleting the existing global.asax file and adding a new one, clears out this error. This has worked for me many times.
If your using visual studio 2010 this error can occur when you change the configuration deployment type. The 3 types are x86, x64 and Mixed mode.
Changing to mixed mode setting for all projects in solution should resolve the issue. Don't forget to delete the bin, Lib files and change the tempdirectory output if your an ASP.NET website.
This just happened to me and after trying everything else, I just happened to notice on the error message that the app pool was set to .Net 1.1. I upgraded the app to 2.0, converted to web application, but never changed the app pool:
Version Information: Microsoft .NET Framework Version:1.1.4322.2490; ASP.NET Version:1.1.4322.2494
This one drove me completely insane and I couldn't find anything helpful to solve it. This is probably not the reason most people have this issue but I just hope that someone else will benefit from this answer.
What caused my problem was a <clear /> statement in the <assemblies> config section. I had added this because in production it had been required because there were multiple unrelated applications on the same hosting plan and I didn't want any of them to be affected by others. The more correct solution would have been to have just used web config transforms on publish.
Hope this helps someone else!
Changing the address's port number (localhost:) worked for me :)
I fixed this error by simply switching from Debug to Release, launch program (It worked on release), then switch back to Debug.
I tried just about everything else, including restarting Visual Studio and nothing worked.
I had this same problem installing my app to a server. It ended up being the installer project, it wasn't installing all the files needed to run the web app. I tried to figure out where it was broken but in the end I had to revert the project to the previous version to fix it. Hope this helps someone...
In my case, a AfterBuild target in the project to compile the web application was the reason for this error.
See here for more info
Removing Language="c#" in global.asax file resolved the issue for me.
In my case, I was duplicating an online site locally and getting this error locally in Utildev Cassini for asp.net 2.0. It turned out that I copied only global.asax locally and didn't copy the App_code conterpart of it. Copying it fixed the problem.
When you try to access the Microsoft Dynamics NAV Web client, you get the following error.
Could not load type 'System.ServiceModel.Activation.HttpModule' from assembly 'System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
This error can occur when there are multiple versions of the .NET Framework on the computer that is running IIS, and IIS was installed after .NET Framework 4.0 or before the Service Model in Windows Communication Foundation was registered.
For Windows 7 and Windows Server 2008, use the ASP.NET IIS Registration Tool (aspnet_regiis.exe,) to register the correct version of ASP.NET. For more information about the aspnet_regiis.exe, see ASP.NET IIS Registration Tool at Microsoft web site.
try this solution
https://www.youtube.com/watch?v=LNwpNqgX7qw
Ensure compiled dll of your project placed in proper bin folder.
In my case, when i have changed the compiled directory of our subproject to bin folder of our main project, it worked.
Had this error in my case I was renaming the application. I changed the name of the Project and the name of the class but neglected to change the "Assembly Name" or "Root namespace" in the "My Project" or project properties.
Deletin obj, bin folders and rebuilding fixed my issue
I had this problem.
I solved it with this solution, by giving CREATOR OWNER full rights to the Windows Temp folder. For some reason, that user had no rights at all assigned. Maybe because some time ago I ran Combofix on my computer.

Resources