No styles / images on asp.Net MVC 2 application

2019-04-22 22:28发布

Greetings

i have a little problem with my ASP MVC application. On my local development server everything works just fine but when i try to publish the application to an IIS 7.0 server it just displays plain pages without any styles / markups / images.

I put all those things in the /Content/ subfolder but when i try to access that folder on the production server it just returns me a 404 not found error.

I set the IIS server up with .Net 4.0 and followed the deployment guide on here: http://www.asp.net/learn/mvc/tutorial-08-cs.aspx

All views / controllers / classes seem to work just fine, the only thing which does not is the content subfolder and i cant see why.

Anyone got a suggestion what i could have overlooked or does anyone know that problem?

6条回答
劫难
2楼-- · 2019-04-22 22:40

Been pulling my hair out all night with this one.

On W2K8, MVC2, .NET 4.0, and IIS 7 (using VS 2010)

Made sure that IIS_IUSRS had full rights to the root folder but still no go - css, js, images still not being accessed in rendering the page....

and then .... so simple:

In Features view for the site - defined MIME types for .js, .css, and .jpg - and voila!

Sweet!

p.s. my 1st mvc app - and I think I'm liking it...

查看更多
放我归山
3楼-- · 2019-04-22 22:51

I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.

When a user is not logged in yet, they are classified as Anonymous Authentication. In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder.

That fixed it for me, hope it works for you.

查看更多
forever°为你锁心
4楼-- · 2019-04-22 22:51

Well, I added the IIS_IUSRs to the project directory and found the same problem:
CSS won't load and nothing from the content folder.
But it resolved the Unable to start debugging on the web server problem.
Then, I added the IUSR to the same folder and that fixed the problem. Now, I can see images, css styles and all that stuff.

查看更多
beautiful°
5楼-- · 2019-04-22 22:51

This is because you are probably using a fixed path on the src, like: ../../Content/Styles/style.css. In MVC you should use the Url helper: Url.Content("~/Content/Styles/style.css").

Using the Url helper you should have no issues.

查看更多
劫难
6楼-- · 2019-04-22 22:51

Check the properties of your content folders...see if they are not 'copying locally' for some reason.

查看更多
Melony?
7楼-- · 2019-04-22 22:54

The folder that your virtual directory is pointing to gave to the user "All" reading properties.

查看更多
登录 后发表回答