Why does Application_Start run in Cassini but not in IIS7? - asp.net

I have an ASP.NET 3.5 sp1 app that's in development in Cassini. The app includes a global.asax file that should run some code - it works fine in Cassini but in IIS the debugger never hits the function. Why doesn't that code run?

Maybe in Cassini, the Application is started when Cassini is launched. In II7, a service, the application is already started and when you launchh the debugger, VS attached only the debugger. You can try to launch the debugger and recycle the pool in the IIS console to see the application restarted ?

You're manually attaching the debugger to the w3wp.exe process? Most likely you're simply too late and the Application_Start already ran by the time the debugger attaches.

Are you sure that the code isn't being executed or could it be that you are simply attaching to the process too late for the debugger to be of any use for it? I'd suggest adding some logging to the method to be sure.

I'm seeing the same issue with a WCF web project running in IIS7. The very first line of code in Application_Start() is a logger write, and I never get it. Also, other objects that are supposed to be initialized on Application_Start never get created and the rest of my code fails because of it. Anyone ever figure anything out with this? It does run fine in Cassini...

Related

Shell.Invoke doesn't launch the powershell script in deployed asp.net web application

I wrote an asp.net web application, which launches a powershell script. The program ran without any issue when I debugged it in my development environment. After publishing and deploying the asp.net web application (by the way the target server is the same machine localhost), by clicking the button for launching the powershell script, nothing happened. It means the powershell script was not launched. I attached the debugger to the deployed asp.net and saw that the Shell.Invoke() was hit as before and the command was also correct. However Shell.Invoke() returned immediately and the powershell script was not launched. In my environment the powershell execution policy is RemoteSigned.
Since the program in the development environment works perfectly and in the deployed case also hits the same code, I don't think it has to do with the code but more with security, certification,...???
Has anyone experienced the same? If yes, please advise me what I should do.
I appreciate your help in advance.
Thx
Might have something to do with the application pool identity not having the right permissions:
You might want to run your PowerShell invocation from a system service with explicit permissions though. That will take a steeper curve though.

Application_Start is not firing in IIS

In my web application, I had given some set of coding's in the APPLICATION_START() in Global.asax file. Its been working while I run it on the development server. Whereas, when I hosted it in IIS, the Application_Start event is not firing. Can any one help me to get rid of this... Thanks in advance.
No idea if this is your situation, but in case it helps, this happened to me with the following conditions:
I am using Microsoft.Web.Infrastructure.DynamicModuleHelper
The IIS application pool is set to use Integrated Pipeline mode (it works ok with Classic)
I do not have a PreApplicationStartMethod defined.
(This arose because I was trying to use Ninject.Web 3.0 in a web forms application. It relies on WebActivator which is unsigned and so I can't use it easily with my signed assemblies. So I tried to call NinjectWebCommon.Start() from Application_Start() manually which works fine with the debug webserver but not with IIS in integrated mode.)

Flakey debug behavior in application start, global.asax

Not using Cassini, but IIS7 to run an ASP.NET app.
The debug behavior is flakey. Sometimes it works, sometimes it doesn't. I was able to step into the application start event in global.asax but sometimes I can't.
Sometimes VS2008 opens the published global.asax so I have two instances of global.asax opened in VS, the source and the published.
I reset the AppDomain and IIS and I can't put my finger on why this is happening. Any clues?
To add, while it won't go into application start, I have an OnChangeEventHandler event - it does step into the event handler.
Visual Studio doesn't connect to w3wp.exe soon enough to handle breakpoints in Application_Start for IIS7-hosted applications. To debug, use the following line to call debugger explicitly,
System.Diagnostics.Debugger.Launch();
and choose to launch a new instance of Visual Studio.
make a change in the web.config, the application pool will recycle and the global.asax code will be loaded, the debugger should still be attached

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

Visual Studio "Unable to start debugging on the web server. The web server did not respond in a timely manner."

I get the following error pretty regularly when compiling in Visual Studio and running my web application:
"Unable to start debugging on the web server. The web server did not respond in a timely manner. This may be because another debugger is already attached to the web server."
Normally this is after having debug the application once already. From the command line I run "iisreset /restart" and it fixes the problem.
How do I prevent this from happening in the first place?
The solution that worked for me:
Open Command Prompt (Run as Administrator)
Write iisreset /restart
Now, go back to your VS and debug. It will debug your solution.
It worked for Visual Studio 2013 and 2015 too in my case.
I find that this happens if I'm debugging with Firefox as my browser. When I exit Firefox the VS2005/8 debug session doesn't terminate. I have not found a solution for this (yet).
If this is what's happening with you then a quicker solution than running iisreset is to hit Shift-F5 when in Visual Studio and this will terminate the current debug session. You can then hit F5 and this will start a new debug session.
After trying all of the proposed solutions here and in other places (at least 10 different approaches), the only option that worked for me was:
delete website and application pool on IIS
re-create website and application pool on IIS (in my case, everything exactly the same config as before)
PS: I am using VS 2013 and IIS 7.5 (Win7).
I hope this saves someone else a few hours.
Go to task manager and end process aspnet_wp.exe before running application
I have had this problem a couple times. One time it was resolved by taking Guy's advice:
If this is what's happening with you then a quicker solution than running iisreset is to hit Shift-F5 when in Visual Studio and this will terminate the current debug session. You can then hit F5 and this will start a new debug session.
On a separate occasion I had to: terminate all my IIS worker processes in the windows task manager (w3wp.exe*). You should be able to hit f5 in visual studio to debug.
It sounds like you are probably hitting F5 in Visual Studio when you receive this error?
There are a few things you can try. The easiest is to hit the Stop button before hitting F5. Optionally, when you are finished debugging and starting to make changes you can go to the Debug menu and choose either Stop Debugging or Terminate All.
We use another way of debugging, we never use F5 anymore.
We use a macro kind of like: http://blogs.conchango.com/howardvanrooijen/archive/2007/06/24/Attach-to-Web-Server-Macro-for-Visual-Studio.aspx (Which we bound to F6).
This way you simply attach the debugger to IIS. It's (depending on project size) much quicker to make you changes, compile a single project that you changed and attach the debugger again.
When debugging 2 web application (1 MVC and 2 is MVC WebAPI) that are both hosted in the local IIS.
Make sure that each application is using a different application pool.
I encountered the same issue and as soon as I change the app pool of the other one, it worked!
I saw this message first time in my life and I was very confused about what is going on as it is not pretty obvious what to do.
I ran iisreset and it took just 1 sec to finish the execution, and boom, I was back into the game.
P.S. I am using chrome
Hit Shift+F5 when in Visual Studio and this will terminate the current debug session. You can then hit F5 and this will start a new debug session.
or
close your application, reset iis then open your application and run it
For me I had two visual studio open. The debugger already was attached to another visual studio :). I stopped it on the first one and was able to attach on the second visual studio.
Very basic - but check that if you try to run the web site from IIS by clicking on "Browse", the site actually runs.
It sounds like something is eating up your web server's resources. Perhaps you have some resources (file handlers, wcf proxies) that are being opened and not closed? I've had this happen to me specifically when I was not closing WCF client proxy connections.
The problem is not necessarily that you have a debugger attached, but only that the web server is not responding in a timely manner. Note that the message says "This may be because another debugger is attached".
If you have a lot of break points this will slow the debugging process down, so remove unneeded break points and close the Autos window this will solve your problem
The issue is normally there when an another instance of iexplore is still running. I used to have the issue when my IE crashes but I can still see it in the Task Manager. Once you "End Process" everything is back to normal :)
I ran into this issue when trying to debug (2) separate solutions in VS.NET and both were using the IIS Web Server to launch the app. The 1st application will start, but any subsequent applications started that also run via IIS will then display that error. It seems that it can only debug a single application via VS.NET hosted in IIS at a time.
The solution: run project 1 from VS.NET (place any needed breakpoints) and start the second application directly from IIS (not VS.NET). Your breakpoints in App 1 (running in VS.NET) will be hit when accessing App 2 (ran from IIS directly).
This happens to me quite a bit in VS 2010 express - Usually because the debugger stopped responding.
Right click windows taskbar, select 'Start Task Manager'. More than likely the ASP.NET debugger will be showing a 'not responding' status. Select it and simply terminate the process.
Done!
With me it happened when IE was upgraded to newer version, went to Installed Updates, removed new version of IE, after computer restarted it went back to old version and problem with debugging was solved
Had the same problem, even after a reboot. Basically did this:
Restart IIS
Clean Solution
Rebuild Solution
Then it started working again.
This can also be caused if your website uses a database connection but the database server is unavailable.
I spent some time trying to resolve this issue in the usual ways, but even after restarting my workstation, the issue remained. Eventually I found that the SQL Server (MSSQLSERVER) service was not running.
It should have been running, as it's set to Automatic, but it was stopped, even after the reboot. All the MSSQLSERVER events in the event log appeared normal, so it remains unknown why it wasn't running, but I have now set it to Automatic (delayed start) in the hope that this will reduce resource contention during startup.
Once I started MSSQLSERVER , the message "Unable to start debugging on the web server. The web server did not respond in a timely manner" no longer appeared and normal service was resumed.
I had to recreate the site/application/virtual directory to make it work after I installed vs2015 update3. Hope this helps someone. ;)
I know this is an old question, but I met the same situation recently and try every solution in this post, and no luck. Finally, I found the solution that works for me:
Close Visual Studio
Find Turn Windows features on or off in Control Panel
Uncheck Internet Information Services in the popup dialog
Restart your computer
Check Internet Information Services in the same dialog, and make sure Internet Information Service -> World Wide Web Services -> Application Development Features -> ASP.NET also been checked
Open Visual Studio, and now your application should be able to run in debug mode
Open
Options and Settings Under the debug
Symbols and unchecked Microsoft Symbol Servers
build solution
iisreset
F5 solution
(Be sure Microsoft Symbol Servers unchecked again)
This worked for me by #mtkachenko
Visual Studio 2012: Unable to attach the process. A debugger is already attached
"I have installed Debug Diagnostic Tool v2.0 and as a result I have Debug Diagnostic Service which is started automatically and attached to one of w3wp processes. After turning off and disabling this service all works fine. So if you get such error check processes in task manager which can capture your w3wp process"
I got it worked by creating a new ApplicationPool in the IIS Server and pointing my application to the new ApplicationPool. I have also deleted the old ApplicationPool
This answer will only apply if you are running your solution through IIS. You will know if this applies to you IF you open up your website/project by doing the following:
From within visual studio-->Open Website--> Local IIS -->Select your project
This error Kicked my butt for 4 hours but finally I found an answer. I first attempted the iisreset /restart. This seemed to slightly help but still received the same error.
What worked for me was going (xp machine) to add/remove programs --> Add/Remove Windows Components--> Click on IIS--> Click on "Details". Be sure to have Front Page Extensions installed if you are debugging through IIS.
If all the answers does not work for you, just end process all IIS related components in task manager. This is what worked for me.
I just solved this problem on my machine.
My problem is that I upgraded IE 9 To IE 10 and I got this error.
Solution : Remove IE 10 and downgrade to IE 9.
Go to "Programs and Features" --> "View recent updates" --> find IE 10---> Uninstall it-->reboot--->ie 9 is back--->debug--->works OK.
Try performing either of the following steps to resolve your issue:
Restart your IIS Server
Clean the Solution of your project then build again
If above steps do not help, you can finally try restarting your machine
In your cmd type iisreset and press enter after that your iis is reset and your application is working perfectly

Resources