{"id":2159,"date":"2016-09-29T12:00:24","date_gmt":"2016-09-29T03:00:24","guid":{"rendered":"http:\/\/ocworld.net\/?p=2159"},"modified":"2024-12-13T15:02:35","modified_gmt":"2024-12-13T06:02:35","slug":"%ed%8e%8c-mvc-5-on-windows-server-2008iis-7","status":"publish","type":"post","link":"https:\/\/www.ocworld.net\/?p=2159","title":{"rendered":"\ud38c) MVC 5 on Windows Server 2008\/IIS 7"},"content":{"rendered":"<p>MVC5\ub85c \ub9cc\ub4e0 \uc0ac\uc774\ud2b8\ub97c IIS7\uc5d0 \uac8c\uc2dc \ud560\u00a0\ub54c\u00a0403.14 \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud588\ub2e4.<\/p>\n<p>\uc774\ub97c \ud574\uacb0\ud558\ub294 \ubc29\ubc95\uc774 \ub098\uc640 \uc788\uc5b4\uc11c \uc801\uc5b4\ub454\ub2e4.<\/p>\n<p>\uc601\uc5b4\ub85c \uae38\uac8c \uc801\ud600 \uc788\uc9c0\ub9cc \uacb0\ub860\uc744 \ub9d0\ud558\uba74 \uc0ac\uc774\ud2b8\uc758 &#8216;web.config&#8217; \ud30c\uc77c\uc5d0 \uc544\ub798\uc758 \ub0b4\uc6a9\uc744 \ucd94\uac00\ud558\uba74 \ub41c\ub2e4.<\/p>\n<pre>&lt;system.webServer&gt;\r\n&lt;modules runAllManagedModulesForAllRequests=\"true\"&gt;&lt;\/modules&gt;\r\n&lt;\/system.webServer&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\ucd9c\ucc98)\u00a0http:\/\/cdonner.com\/mvc-5-on-windows-server-2008iis-7.htm<\/p>\n<p>I have been working on a small Website built with Visual Studio 2013, .Net 4.5, Entity Framework (code-first), and MVC 5. I started out with the MVC template for responsive sites that includes Bootstrap. Everything went smoothly until I deployed the site to our QA server.<span id=\"more-1729\"><\/span><\/p>\n<p>This box runs Windows Server 2008 x64 (no, not R2). I naively published my app to a local folder and copied everything to the server folder that I created for the new website. After I updated the connection string in the <em>web.config<\/em> and started the site, I\u00a0got the ominous<\/p>\n<p><code>HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory.<\/code><\/p>\n<p>when I tried to hit the home page. Little did I know that it would take me the next 6 hours to figure out what was going on. Because I had to once again sift through <a href=\"http:\/\/stackoverflow.com\/questions\/2374957\/asp-net-mvc-on-iis-7-5\" target=\"_blank\">so much misinformation<\/a>on the web about this issue, I am going to\u00a0write\u00a0up\u00a0what I found.<\/p>\n<h3>IIS Configuration<\/h3>\n<p>Common things to check when a\u00a0website does not run properly are<\/p>\n<ul>\n<li>The app pool configuration\n<ul>\n<li>pipeline mode<\/li>\n<li>target .Net framework (4.0.30319 is the latest, and 4.5.1 is installed)<\/li>\n<li>credentials<\/li>\n<\/ul>\n<\/li>\n<li>Folder security (allow access for the app pool user)<\/li>\n<li>Website security (anonymous access is needed for my site)<\/li>\n<li>Re-register ASP.Net by running <em>aspnet_regiis<\/em> ad nauseam<\/li>\n<\/ul>\n<p>None of these things applied, though, because I had done a thorough job installing .Net 4.5.1 and configuring my site.<\/p>\n<h3>Deployment Method<\/h3>\n<p>Because IIS seemed to be set up and configured correctly for my website, I looked at the way I deployed. Maybe something was missing?<\/p>\n<p>I installed the Web Platform Installer on our server and added the Web Deploy plugin (3.5). This is required if you want to either use the one-click deployment from Visual Studio or use the Web Deployment Package script that Visual Studio generates. I removed my website from the server, recreated it from scratch, and tried\u00a0both deployment\u00a0methods in Visual Studio with the same results.<\/p>\n<p>From the error message it appears that MVC is not working properly. IIS is looking for a default page to load, does not find one in the root of an MVC site,\u00a0and can\u2019t show the folder content because folder browsing is disabled. But why? Clearly this has to do with the way requests are routed to the correct module in IIS, and somewhere this process is broken.<\/p>\n<p>There are dozens of questions on Stackoverflow related to this issue with answers all over the map, some trivial, some complex. I came back to the same recommendation, though, because nothing else seemed to apply: <a href=\"http:\/\/stackoverflow.com\/questions\/4567844\/what-is-the-correct-usage-of-runallmanagedmodulesforallrequests-in-asp-net-mvc\" target=\"_blank\">adding these lines<\/a> to the\u00a0web.config:<\/p>\n<pre>&lt;system.webServer&gt;\r\n&lt;modules runAllManagedModulesForAllRequests=\"true\"&gt;&lt;\/modules&gt;\r\n&lt;\/system.webServer&gt;\r\n<\/pre>\n<p>There are valid concerns about implementing such a drastic measure, though, for example by<a href=\"http:\/\/weblog.west-wind.com\/posts\/2012\/Oct\/25\/Caveats-with-the-runAllManagedModulesForAllRequests-in-IIS-78\" target=\"_blank\">Rick Strahl<\/a> or\u00a0<a href=\"http:\/\/www.britishdeveloper.co.uk\/2010\/06\/dont-use-modules-runallmanagedmodulesfo.html\" target=\"_blank\">by this chap<\/a>. I tried to add this manually to my <em>web.config<\/em>,\u00a0but only got an error. My IIS did not understand\u00a0the <code><\/code> section, even though I followed <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb763179(v=vs.100).aspx\" target=\"_blank\">the documentation<\/a> closely.<br \/>\nNone of the hot fixes that were referenced in these posts worked for me (for example <a href=\"http:\/\/support.microsoft.com\/kb\/980368\" target=\"_blank\">this one<\/a> or<a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?displaylang=en&amp;id=5272\" target=\"_blank\">this one<\/a>), presumably because I am on Server 2008 and not R2, and when I tried to install, I would only get the\u00a0message that the hotfix does not apply to my server. And by the way, the server is current with patches, so any hotfixes would have been applied in the past anyway.<\/p>\n<h3>Managed Modules<\/h3>\n<p>The bin folder contained all the necessary assemblies for MVC (MVC 5 does not need to be deployed as a prerequisite because it is part of the web site deployment package).<\/p>\n<p>And yet, for some reason, MVC did not rewrite the URL to invoke the correct handlers for my site. So, after more poking around in various Stackoverflow articles and blog posts I had a break-through when I finally came across <a href=\"http:\/\/blogs.msdn.com\/b\/amol\/archive\/2011\/04\/14\/forms-authentication-for-non-aspx-files.aspx\" target=\"_blank\">this one on MSDN<\/a>. It explains how to use the IIS Manager\u2019s GUI to explicitly add the UrlRoutingModule to the web.config, even though it showed up as installed for my site:<\/p>\n<div id=\"attachment_1735\" class=\"wp-caption aligncenter\">\n<p><a href=\"http:\/\/cdonner.com\/wp-content\/uploads\/2013\/12\/urlrouting.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1735 \" title=\"UrlRoutingModule 4.0\" src=\"http:\/\/cdonner.com\/wp-content\/uploads\/2013\/12\/urlrouting.png\" sizes=\"auto, (max-width: 670px) 100vw, 670px\" srcset=\"http:\/\/cdonner.com\/wp-content\/uploads\/2013\/12\/urlrouting.png 670w, http:\/\/cdonner.com\/wp-content\/uploads\/2013\/12\/urlrouting-300x116.png 300w\" alt=\"UrlRoutingModule 4.0\" width=\"670\" height=\"260\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">UrlRoutingModule 4.0<\/p>\n<\/div>\n<p>After I unchecked the <em>\u201cInvoke only for requests to ASP.NET applications or managed handlers\u201d<\/em>checkbox the Entry Type changed to <em>Local<\/em> (see the screen shot above) and\u00a0a corresponding section appeared in my web.config. IIS suddenly began to understand <code><\/code> section (I still don\u2019t know why), and the site started to render MVC views.<\/p>\n<p>The section that was added, btw, is this one:<\/p>\n<pre>&lt;system .webServer&gt;\r\n&lt;modules&gt;\r\n&lt;remove name=\"UrlRoutingModule-4.0\"&gt;&lt;\/remove&gt;\r\n&lt;add name=\"UrlRoutingModule-4.0\" type=\"System.Web.Routing.UrlRoutingModule\" preCondition=\"\"&gt;&lt;\/add&gt;\r\n&lt;\/modules&gt;\r\n&lt;\/system&gt;<\/pre>\n<p>I had seen this before at this point, but only now it made sense to me. What still does not make sense to me is why this was necessary and why<br \/>\na. Visual Studio had not included this in the web.config<br \/>\nb. The routing module was not invoked without this setting.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MVC5\ub85c \ub9cc\ub4e0 \uc0ac\uc774\ud2b8\ub97c IIS7\uc5d0 \uac8c\uc2dc \ud560\u00a0\ub54c\u00a0403.14 \uc5d0\ub7ec\uac00 \ubc1c\uc0dd\ud588\ub2e4. \uc774\ub97c \ud574\uacb0\ud558\ub294 \ubc29\ubc95\uc774 \ub098\uc640 \uc788\uc5b4\uc11c \uc801\uc5b4\ub454\ub2e4. \uc601\uc5b4\ub85c \uae38\uac8c \uc801\ud600 \uc788\uc9c0\ub9cc \uacb0\ub860\uc744 \ub9d0\ud558\uba74 \uc0ac\uc774\ud2b8\uc758 &#8216;web.config&#8217; \ud30c\uc77c\uc5d0 \uc544\ub798\uc758 \ub0b4\uc6a9\uc744 \ucd94\uac00\ud558\uba74 \ub41c\ub2e4. &lt;system.webServer&gt; &lt;modules runAllManagedModulesForAllRequests=&#8221;true&#8221;&gt;&lt;\/modules&gt; &lt;\/system.webServer&gt; &nbsp; \ucd9c\ucc98)\u00a0http:\/\/cdonner.com\/mvc-5-on-windows-server-2008iis-7.htm I have been working on a small Website built with Visual Studio 2013, .Net 4.5, Entity Framework (code-first), and MVC 5. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[186,184,185],"class_list":["post-2159","post","type-post","status-publish","format-standard","hentry","category-info","tag-asp-net","tag-iis7","tag-mvc5"],"_links":{"self":[{"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/posts\/2159","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2159"}],"version-history":[{"count":5,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/posts\/2159\/revisions"}],"predecessor-version":[{"id":2165,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=\/wp\/v2\/posts\/2159\/revisions\/2165"}],"wp:attachment":[{"href":"https:\/\/www.ocworld.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ocworld.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}