I have created an MVC 3 app using a pretty standard setup. My _ViewStart file specifies that _Layout should be used and my CSS and JS fi开发者_运维问答les are included in the _Layout file.
When I debug and navigate to /Home/Index, my page looks exactly as I would expect. My site is styled properly and all of my javascript includes are present.
When I publish this site to an IIS server, and then navidate to /Home/Index, the site loads, but the page has no styles or javascript. When I view the source, I can see that all IIS did was serve Index.cshtml directly, without first combining it with _Layout. I can't figure out why it works in debug, but not in IIS. Could it be a permissions issue?
SOLVED
I submitted my solution below. I will accept it once the 48 hour waiting period is over.
One possibility for not seeing styles is that you hardcoded the urls for your custom javascript and CSS files, like this:
<link href="/Content/MyStyle.css" rel="stylesheet" type="text/css" />
instead of using url helpers:
<link href="@Url.Content("~/Content/MyStyle.css")" rel="stylesheet" type="text/css" />
so that the virtual directory that you have hosted your application in IIS is no longer taken into account.
If you cannot see the contents of _Layout.cshtml make sure that it has been deployed in IIS along with _ViewStart.cshtml
. There is no reason for IIS not serving those files.
Boom, solved it.
My application pool was running as the wrong user. That particular user did not have read access to my application's directory.
It was very similar to this post, but I was not getting any sort of error.
Thanks, everyone!
Are you using IIS7 by any chance? If yes, make sure you have the static content services enabled:
http://weblogs.asp.net/anasghanem/archive/2008/05/23/don-t-forget-to-check-quot-static-content-service-quot-in-iis7-installation.aspx
http://technet.microsoft.com/en-us/library/cc732612(WS.10).aspx
精彩评论