IIS 8.5 - Application initialization not working - asp.net-mvc

I have installed Application Initialization, set the website's application pool Start Mode to "Always Running", and set Preload Enabled = "True" in the advanced settings of the website.
However, if I recycle the application pool manually and wait 10 seconds, when I then reload the website, I still have to wait another 10 seconds for the website to warm up. This indicates that the website is not starting.
Looking at task manager, I can see that the application pool is running the whole time - even after a recycle. However, the memory usage is very low until I make my own request to the website.
One thing I have noticed is that I do not have a "Start Automatically" setting in the advanced settings of my website as per this link:
https://blogs.msdn.microsoft.com/vijaysk/2012/10/11/iis-8-whats-new-website-settings/
How can I get my application to auto-start?

It turned out to be a whole load of settings which all had to be correct. You go through all of the steps to install the relevant components and make the various config changes as per this link: http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization
The key part which was missing for me was an instruction in the Web.config as below. I had it going to just "/Login" which is a valid route, but as soon as I switched it to "/[Controller]/[Action]" it worked.
The advantage of this route is that you can create a custom action which will also hit the database (initialising Entity Framework), and perform any other slow initialisation you wish. For me, I just read a record out of a DB table, so I get ASP.NET auto-starting, and also save the few seconds it takes to warm up EF too :)
<system.webServer>
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
<add initializationPage="/Login/WarmUp" />
</applicationInitialization>
</system.webServer>

Try Application Initialization setup:
I had similar issues and tried very hard with IIS 8.5 Windows Server 2012 R2. Everything in the IIS was set correctly after referring to so many sites however had missed the Application Initialization setup. Refer to the below link, Setup section.
https://www.iis.net/configreference/system.webserver/applicationinitialization

There are multiple .config locations where these settings can be set.
Machine applicationHost.config (c:\windows\system32\inetsrv\Config)
Website web.config (c:\inetpub\wwwroot for Default Web Site)
Application web.config
I tried all but was only successful in configuring 3, the application web.config.
My specific use case was calling a GET method on a WCF service.
The steps for application initialization are found in the other answers too. Here is one that was most helpful. IIS 8.0 Application Initialization
Install the Windows feature Application Initialization (Web-AppInit)
Set the IIS app pool Start mode = AlwaysRunning
Set the IIS application Preload Enabled = true
Add to the application web.config
<system.webServer>
<applicationInitialization doAppInitAfterRestart="true" skipManagedModules="true">
<add initializationPage="/Service.svc/Method/Parameter" />
</applicationInitialization>
</system.webServer>
Recycle app pool
Check that the app initialized.
The thing I would like to point out is that the initialization page is relative to the application NOT to the root of the website/domain so if my absolute path is
domain.com/path1/path2/Service.svc
I would not include /path1/path2 in the initializationPage parameter.

These articles are very good:
Use IIS Application Initialization for keeping ASP.NET Apps alive
IIS 8.0 Application Initialization
However in my case there was a problem with installing the Application Initialization Role.
Check your IIS App's Modules listing. Ensure ApplicationInitializationModule is present.
I needed to uninstall/re-install this module.
I have no idea what happened as this appeared to work at first, then weeks later during development it stopped. No amount of tinkering/rework fixed it and I started to suspect I never actually saw this working.
Issue resolved upon uninstall/re-install Applicaion Initialization Module role.

If anyone's wondering what to do in MVC when you have multiple areas to initialise, you need to put the area at the start, all within the root web.config file. I was stuck for a while trying to put it in the area's web.config. Also it's perfectly compatible with hybrid applications.
<add initializationPage="/NotMVC.aspx" />
<add initializationPage="/Area1/Controller/Action" />
<add initializationPage="/Area2/Controller/Action" />

Related

How does application Initialization in IIS work?

I configured my IIS website to be always up and to initialize it after pool recycle. But I'm not sure how it works. This is .NET 6 MVC app.
All instructions say that I need to install Application Initialization role, but "Preload enabled" setting was available for my website even before installing this role. I set it to true but it didn't seem to work. I installed Application Initialization and it started working.
So the first question is what does "Preload enabled" setting do when you don't have Application Initialization installed?
I assume that with above settings IIS is making a request to my Home page. But I'm not sure I will have this page in final version of application.
The second question is, if I remove Home page will auto preloading stop working? If yes, then I need to use applicationInitialization settings in config file and configure it like this?
<add initializationPage="/CustomWarmupPage" hostName="myhost" />
So the first question is what does "Preload enabled" setting do when
you don't have Application Initialization installed?
Starting with IIS 8, application initialization is part of the IIS feature set. For IIS 7 and 7.5, it is available as a separate download through the Web Platform Installer. Application initialization with IIS 8 is an optional installation component in Windows or Windows Server Role Manager.
To support application initialization on your Web server, you must install the Application Initialization role or feature. If application initialization is not installed, the "Preload enabled" setting will have no effect.
The second question is, if I remove Home page will auto preloading
stop working? If yes, then I need to use applicationInitialization
settings in config file and configure it like this?
<add initializationPage="/CustomWarmupPage" hostName="myhost" />
The way this module works is that you introduce a path, and when your ApplicationPool runs, it sends a request to the registered path. System startup should not be delayed until the first request is sent to the program. To do this, you must enter the following command in the system.webServer tag of the web.config file,like:
<applicationInitialization doAppInitAfterRestart="true"
skipManagedModules="true" >
<add initializationPage="/default.aspx" />
</applicationInitialization>
Using the above command, we specify that after the ApplcationPool starts, it will send a "/default.aspx" request to the path entered in the initializationPage parameter, which is the initial setup of the service. Then you need to set the Application Pool Start Mode value to AlyawsRunning and the WebSite PreLoad Enebled value to true to do this automatically. This will always send a request to warm up the app when the app starts or restarts.

Deploying ASP MVC 5 App with IIS 7.5

I try to deploy ASP MVC 5 app in virtual directory (without creating new iis application)
I use IIS 7.5
I already put
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true" />
in web.config file.
But when i go to app url with IE browser it shows me just directory listing like in screenshot below
Is there a way to deploy MVC 5 in virtual directory and make it work like usual MVC application?
You need to convert the virtual directory to application. Right click on it in the IIS management console and choose Convert To Application.... Also make sure that the associated application is configured to use Integrated Pipeline Mode.
I solved this problem earlier in my production environment by checking the directory pointer in IIS. Apparently when I unzipped the deployed site from one server to the next, the zip utility made an extra level, so IIS was pointing to /MyProject when the files were in /MyProject/MyProject. I had a little better clue though, you have Document Browsing enabled based on that screen shot, make sure not to do that in production. I set the site to log custom errors and got a 403.14 response, from there found a blog on my mistake. You need to setup the environment to find the specific module that's failing, I think something to do with trace routes, idk. I'm a software developer that always gets forced into doing devOps; was googling my own problem and thought I'd throw you a line. Without a specific error message, all I can tell you is IIS is not connecting to .NET; something is not configured correctly. Turn off directory browsing, google how to get good error logs back, and let us know the status code so we can help you: 403.14, 401, 500, 404? Also give us the module that's failing. If it's the last one on the handler list, guess what, IIS isn't connecting to the app, which I suspect is your case.

ASP.NET Azure project does not appear to load newest content items

I have an ASP.NET MVC project and I am testing deployment to Windows Azure via the local emulator. I can run the project file fine in the development server but when I build the Azure project and it launches via the emulator I am having an issue with content files not being returned correctly. My internal CSS and JS files are being re-directed to the login page as if the authorization is failing; however I do not see where this auth requirement would be coming from.
Things I have already tried:
I have manually removed all the build files from both project (I have also tried the "clean" action for the solution)
I have tried removing the Azure project all together and creating a new one from the current version of my project.
I have tried clearing the local storage through the Azure storage interface.
I have verified that all my content is marked as "Content" in my ASP.NET project.
I have tried flagging all of my content items as "Copy always"
I have verified that the Static Content optional feature is checked
EDIT: I did a deploy to the web and everything works great there ... this is an emulator issue it appears. Any suggestions with that new bit of info?
You should verify your web.config just to be sure. Do you see something like this?
<system.web>
<authorization>
<deny users="?" />
</authorization>
...
</system.web>
Did you put the [Authorize] attribute on some of your controllers, or your controller base?
If it works in the cloud and in ASP.NET Development Server, I am not very sure why it doesn’t work in emulator. However I don’t think the issue is related to your application. For now, I would like to suggest you to check your IIS settings, such as applicationHost.config. Please see if there’re any authorization settings that may cause this issue(Compute Emulator uses IIS under the hook to host web roles). Please also try to host the site in a local IIS directly and see if the same issue could be encountered. If you can reproduce this issue in IIS as well, I would recommend you to consider to add a “IIS” tag to this thread, so more IIS experts will provide further suggestions.
Best Regards,
Ming Xu.
This thread has been open for a long time so I wanted to close it with what ended up being the solution.
It ended up being a bug with the emulator and the environment being used. As I mentioned, I was able to get it working when deployed. I actually tried this same situation 6 months later after updating to the latest Azure tool set and it worked fine so I am chalking this up to a bug in the emulator that has since been resolved.

Getting 404 error on MVC web-site

I have an IIS7.5 web-site, on Windows Server 2008, with an ASP.NET MVC2 web-site deployed to it. The website was built in Visual Studio 2008, targeting .NET 3.5, and IIS 5.1 has been successfully configured to run it as well, for local testing.
However, whenever I try and navigate to a page running in IIS7, I get a 404 error.
I have checked the following things:
There is no corresponding 404 log entry in IIS logs.
Actually, there are 404 entries in the IIS log.
The application pool for the web-site is set to use the Integrated pipeline.
The "customErrors" mode is set to off.
.NET 3.5 SP1 is installed
ASP.NET MVC 2 is installed
I've used MVC Diagnostics to confirm all MVC DLLs are being found.
ASP.NET is enabled in IIS, which we've demonstrated by running the MVC Diagnostics page.
KB 2023146 did highlight that HTTP Redirection was off, so we've turned it on, but no joy.
EDIT
Ok, so we've installed the world's simplest MVC application (the one which is created when you create a new MVC2 project in Visual Studio), and we are still getting 404s on any page we try and access - e.g.
<my_server>/Home/About will generate a 404.
Any ideas will be greatly appreciated!
This is quite often caused by the following missing from the web.config:
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
Do you have a problem with just 1 page or the whole site is not working?
A) 1 page
You can use RouteDebugger to verify if the route is matched correctly
B) Whole site
I assume you're using Windows Server - check if ASP.NET is enabled in IIS - it's disabled by default, I believe.
You can use MvcDiagnostics page to check if all dlls are deployed properly.
Are you running in IIS7 integrated mode? Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6)
Make sure your Web.config tag is configured correctly.
We finally nailed this issue by exporting the IIS configuration of a working server, and comparing it to ours.
It was a really obscure setting which had been changed from the default.
IIS ROOT → request Filtering → Filename Extensions Tab → Edit Feature Settings → Allow unlisted file name extensions
This should be ticked.
This can be set at the IIS level, or the site-level.
Glad that fixed your problem. Others researching this issue should take note of the extensionless URL hotfix: http://support.microsoft.com/kb/980368
If none of the other solutions here solved your issue, check that you have the
Global.asax
file in your website. This solved the issue for me.
Checkout if KB 2023146 applies to your scenario. Also try requesting directly a controller action: /yoursitename/home/index
Apparently this can have many different causes.
For us, the problem was that the DNS entry was configured for two IP addresses, but the IIS configuration would only listen to one of them. So we got unpredictable results, sometimes it would work, sometimes a few files (css, etc) would not load, and sometimes the whole page would not load.
For me it was all about installing .NET Framework 4.6.1 on the server (my app was targeting that version)
You'll also get this if your bindings aren't correct. If you don't have www or a subdomain it'll return a 404.
I had this problem when running my MVC4 site with an app pool set to ASP.NET 4.0 and the Classic pipeline, even though the extension handlers were set in my web.config and were showing correctly in IIS. The site worked in Integrated Pipeline so I knew it was a configuration issue, but I couldn't nail it down. I finally found that ASP.NET 4 was disabled for the server in the ISAPI and CGI Restrictions settings. I enabled ASP.NET 4.0 and it worked.
In addition to checking if you're running in integrated pipeline mode, make sure your application pool is set to use .NET! I recently ran into this problem, and when I went in to check the app pool settings, I found that somehow it had been set to "No Managed Code." Whoops!
My Hosting company fixed this for me by doing this (I removed the original password value of course).
<system.webServer>
<security>
<authentication>
<anonymousAuthentication password="<password>" />
</authentication>
</security>
</system.webServer>
Typically I encounter this issue when there is a Routing problem. I compare a working vs non-working to resolve it.
Today however I accidentially created a Virtual Directory in IIS.
It has to be an Application, right click on the Virtual Directory (with a folder icon) -> Convert to Application:
Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>

Internal Server Error due to config lockdown when deploying my ASP.NET MVC app to my web host

I'm developing an ASP.NET MVC website on a local Windows Server 2008/IIS7 machine and am I'm now attempting to deploy it to my web host provider, ASPnix. I'm using their Shared Web Hosting service and have been placed on an IIS7 server which they claim supports ASP.NET MVC.
However, when I deploy the application up to their servers, I get an "Internal Server Error".
Here's the Error Summary:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Here are the relevant portions of the Detailed Error Information:
Module: IIS Web Core
Notification: BeginRequest
Handler: Not yet determined
Error Code: 0x80070021
Config Error: This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault="Deny"), or set explicitly by a location tag with overrideMode="Deny" or the legacy allowOverride="false".
And the Config Source looks like this:
144: </modules>
145: <handlers>
146: <remove name="WebServiceHandlerFactory-Integrated"/>
The error is coming from the fact that I have a system.webServer section in my web.config file that has a handlers child section. The system.webServer section is the exact config section that was laid down by default when I first created the ASP.NET MVC website in Visual Studio. It has the following XML comment above it:
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
I take the handlers child section out, and the 500 error goes away. Of course, that section is required for an ASP.NET MVC application to work properly in IIS7, so simply taking it only produces other errors (404 errors in this case since routing doesn't work).
The support engineers at ASPnix claim that ASP.NET MVC is installed and configured properly in IIS7 on their servers. I'm not saying I don't believe them as this is the first ASP.NET MVC site that I've built and deployed. However, I can't think of anything I could do to make this work since it appears to be a config issue at a level that I don't have access to.
This issue smells like it would be a common issue with folks trying to deploy ASP.NET MVC to a hosting provider. Has anything run into this either with ASPnix or other web hosting companies and hopefully found a solution?
ps
One odd thing. When researching this issue on the web I find many people saying they had to set the overrideModeDefault attribute their applicationHost.config files of IIS7 to from "Deny" to "Allow". However, my local development server has this set to "Deny" and everything works fine. Even so, I don't have access to the applicationHost.config file anyway on the web host's server.
Open IIS Management, Under the main server node, select open Feature Delegation (in Management section)
"Handler Mappings" to "Read/Write" instead of "Read Only"
It looks like your hosting provider unnecessarily locked down IIS.
I was able to recreate the problem on my local IIS 7.5 server.
See this for a global settings reset.
please check if you deployed your application properly : Deploying an ASP.NET Server (IIS 7)
The link to
http://www.winservermart.com/Howto/HTTP_Error_500_19_IIS_7.aspx
doesn't fix the problem. The "reset delegation" creates an exception in web.config for a particular domain only which makes the site work, but doesn't answer how to set it permanently system wide.
So, it's not shame, because we know the solution and set all settings correctly. And advertising here some other hosts pointless we have tons of clients that are running from wh4l and describing how great their overloaded servers.
-Polk

Resources