IIS isn't serving javascript and css requests on azure webrole application - asp.net-mvc

need your help with this one, i'm running azure deployment on my localhost and get the webpage without css and javascript, when i look in fiddler i see 500 status and the following error: "It is an error to use a section registered as allowDefinition='MachineToApplication' beyond application level. This error can be caused by a virtual directory not being configured as an application in IIS" on each request for javascript or css file, i already enabled static content on windows feature and it didn't help, i'm using iis 7.5 on windows professional 64 bit with azure sdk 1.7, tried anything, and nothing helped, can't change the site to web application cause the website only exist on iis while i'm running debug, any idea what to do?

Could it be that the directory from which you're serving JS/CSS files contains a web.config file? If this is the case this will be causing the problem.
Your web.config contains an element which can only be defined in a real web application (in the root of your application for example- or in the machine.config. To fix this issue you'll need to open the machine.config (C:\Windows\Microsoft.Net\Framework\v4.0.30319\Config\machine.config) and look at each configSection defined here that is also included in your web.config (in the folder containing the JS/CSS files).
If the configSection in the machine.config contains the allowDefinition attribute with MachineToApplication as value this means you cannot use that configSection in a web.config that isn't located in a web application. Meaning in your case you'll need to remove that configSection from the web.config in the folder containing the JS/CSS files.
If you're using ASP.NET MVC this is probably your Content folder.

Related

MVC app static files are not accessible when deployed in virtual folder

I have a Windows Server 2012R2 running IIS version 8.5.9
Currently it has a single ASP.net Forms web application running on the default http port 80.
The website has an application pool (v4.0 Classic).
The website files are stored in c:\inetpub\wwwroot\formsApp.
( The application can be accessed in a way similar to: http://server-host-name.company.com )
This works fine, with no issues.
I created a new ASP.Net MVC application and published it to c:\inetpub\wwwroot\mvcApp.
I also created a dedicated pool (v4.0 Integrated) and configured it to run on port 8080.
The application works perfectly when I visit: http://server-host-name.company.com:8080.
Now, I created a virtual folder in the formsApp website in IIS and pointed it at mvcApp folder.
I also made sure that the pool used for the virtual folder is the Integrated pool, not the classic. The virtual folder name is mvc.
I could tell that IIS did something special to that folder, since its thumbnail icon is no longer a normal folder, but an application website thumbnail.
Now when I go to http://server-host-name.company.com/mvc I can see the page being loaded and the correct controller is called, the view is rendered, but the static script and CSS files are not loaded. When I examined the network log in the browser, I noticed that any request to the script or CSS static content is redirected to the Login Page, since the MVC app has Forms Authentication.
I have looked everywhere how to resolve this issue. Some answers pointed out that I should add a line in Web.config to add the line
<modules runAllManagedModulesForAllRequests="false" />
But that did not work. it had no effect, as the same page loaded without CSS or JS. But besides the fact that it worked or not, it does not explain why the app worked fine when IIS served it off of port 8080, without having that line included in Web.config.
Edit: Just to clarify, after the app runs from the virtual directory, the links/urls to the static files are valid with the name mvc prepended to them as expected.
How can I resolve this issue?

How to precompile MVC for intranet?

VS2013 Update3, .Net 4.5, MVC, IIS 7
I created a new mvc project.
Tested from VS and it works.
From IIs, I created a folder in wwwroot, and made it an application. Add app pool with .net 4.0. Enabled windows authentication and disabled Anonymous authentication. Set service account in app pool and webapp.
From VS I deploy to IIS with default settings (which is NOT precompile) (using File System)
Site works fine on IIS.
But…
If deploy with the precompile setting clicked on. Web site fails with 403 error. Tried various combinations and get never get the precompiled to work. Always works when non-precompiled.
ASP.NET 4 was is registered in IIS.
Tried modules runAllManagedModulesForAllRequests="true" with no success.
I'm out of ideas and looking for help
Server Error in Application "xxx/MVCHELLOWORLD"
Internet Information Services 7.5
Error Summary
HTTP Error 403.14 - Forbidden
The Web server is configured to not list the contents of this directory.
Detailed Error Information
Module
DirectoryListingModule
Notification
ExecuteRequestHandler
Handler
StaticFile
Error Code
0x00000000
Requested URL
http://xxx/MvcHelloWorld/
Physical Path
C:\inetpub\wwwroot\MvcHelloWorld\
Logon Method
Negotiate
Most likely causes: •A default document is not configured for the requested URL, and directory browsing is not enabled on the server.
Things you can try: •If you do not want to enable directory browsing, ensure that a default document is configured and that the file exists.
• Enable directory browsing using IIS Manager. 1.Open IIS Manager.
2.In the Features view, double-click Directory Browsing.
3.On the Directory Browsing page, in the Actions pane, click Enable.
•Verify that the configuration/system.webServer/directoryBrowse#enabled attribute is set to true in the site or application configuration file.
Links and More InformationThis error occurs when a document is not specified in the URL, no default document is specified for the Web site or application, and directory listing is not enabled for the Web site or application. This setting may be disabled on purpose to secure the contents of the server.
View more information »
I just had the same issue and have been trying to resolve it for the last couple of days.
I have a Windows 8 pc running IIS 8 Express.
I copied an MVC site that was compiled and published from another pc, ran it, and got the same 403.14 forbidden as above. I then tried publishing the site uncompiled and running it and the site loaded just fine.
I then decided to load Visual Web Express on the Windows 8 pc and created a dummy MVC site and ran it compiled and uncompiled and it worked just fine. This showed me that IIS 8 Express was configured and working properly and there must be some issue in the way the site was compiling.
I tried different precompile methods during the publish including do not merge, merge all and merge each folder but none of those many any difference.
In the end I solved this by changing the Copy Local property to true for every Assembly referenced within the project. Even all the default ones that should be referenced from the GAC.
Not sure if I needed to copy every assembly to the bin folder or not but given the large number of assemblies referenced within my project this seemed easier then trying them 1 by 1.
EDIT: Made some changes and republished the site and now I'm back to the 403.14 forbidden again :(
I'm really pulling my hair out on this one as to why it isn't working.

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.

Issue hosting ASP.NET MVC 4 application using IIS 7.5 after creating virtual directory - Script files are not working

I have an ASP.NET MVC 4 application that I am trying to host in IIS 7.5. I tried creating a virtual directory using "Use Local IIS Web server" option in Project properties and have set the Anonymous Authentication and Windows Authentication set in IIS.
When I run the application, it opens in the browser with the url, "http://localhost\ApplicationName" and I am able to view only the tab names I have created. When I right click and view the page source, I have my scripts listed and the body defined with divs and tables. When I click the tab names, nothing happens.
In the view page source, when I click any script, it throws an error,
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information
Module IIS Web Core
Notification MapRequestHandler
Handler StaticFile
Error Code 0x80070002
Requested URL http://localhost:80/Scripts/Script.js
Physical Path C:\inetpub\wwwroot\Scripts\Script.js
Logon Method Anonymous
Logon User Anonymous
In IIS, I have enabled Anonymous, ASP.NET Impersonation and Windows Authentication.
Also, When I look at the Advanced settings for the directory, it shows the physical path in C\Users........ but in the Detailed Description, it shows the Physical Path as "C:\inetpub\wwwroot\Scripts\Script.js".
Am I giving the path wrong? or should I place the project files in "C:\inetpub\wwwroot\Scripts\Script.js"?
Please help. I have been struggling with this for a while now and it's driving me crazy.
Are you using URL Bundles or are you manually hard coding .JS paths in your front-end code? Are you seeing good/expected behavior when you run the site in debug mode within Visual Studio? I would try and gather some hints with those considerations and perhaps furnish some more information...

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