2

I have deployed my MVC app but when I browse from IIS I find that the forms authentication seems to block the CSS. This does not happen on my dev server. Why would this happen? My master page look like this;

<head id="Head1" runat="server">
    <title><asp:ContentPlaceHolder ID="TitleContent" runat="server" /></title>
    <link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
    <script src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.js" type="text/javascript" language="javascript"></script>
    <script src="http://nje.github.com/jquery-tmpl/jquery.tmpl.js" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/jquery.form.js")%>" type="text/javascript"></script>
    <!-- note that the order scripts are included in is important -->
    <script src="<%=Url.Content("~/Scripts/jquery.Validate.js")%>" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/MicrosoftMvcJQueryValidation.js")%>" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/ConfusedValidation.js")%>" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/Awesome.js")%>" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/MicrosoftAjax.debug.js") %>" type="text/javascript"></script>  
    <script src="<%=Url.Content("~/Scripts/MicrosoftMvcAjax.debug.js") %>" type="text/javascript"></script>
    <script src="<%=Url.Content("~/Scripts/jquery.jcacher-1.0.0.min.js")%>" type="text/javascript"></script>
    <link href="<%=Url.Content("~/Content/jquery.ui.autocomplete.css")%>" rel="stylesheet" type="text/css" />

    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/overcast/jquery-ui.css" 
            type="text/css" rel="Stylesheet" class="ui-theme" />

    <link href="<%=Url.Content("~/Scripts/Awesome.css")%>" rel="stylesheet" type="text/css" />

* EDIT * In Firebug I get the message; Failed to load source for: http://192.168.100.999/Content/Site.css In fact I get this for all the local files.

2
  • 2
    Just a tip: If possible, you may want to move all of your javascript references to the bottom of your page, it will speed up your page load time: developer.yahoo.com/performance/rules.html Commented Mar 22, 2011 at 12:19
  • I very much appreciate tips like that. Thank you. Commented Mar 22, 2011 at 14:43

6 Answers 6

11

I have also faced the same kind of problem. My local server IIS configuration was not working but Development server worked properly. That time had to add "User Permission" to my Hosed folder by right click on hoted site in IIS.

Just follow the step. enter image description here

and then add uesr called IUSER by Add User panel.

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it fixed my problem. Do u know the reason why this is necessary?
that is because your application pool uses IUSR as the user accessing the folder; thus, you need to give that user a permission to the folder to access it; otherwise you will get permission denied (403)
4

Are you on shared host? Does yours script *.js load? If it does it means youre relative path is not good, you probably could refer to your css file the same way you do to your .js using Url.Content.

<link href="<%=Url.Content("~/Content/Site.css)%>" rel="stylesheet" type="text/css" />

I suggest you to take a look at SquishIt : http://www.codethinked.com/squishit-the-friendly-aspnet-javascript-and-css-squisher it will combine and minimize your CSS and javascript for browser optimization.

Hope it helps!

5 Comments

and what about my questions? Shared hosting? Does your other script.js load?Can you put more code like the source or maybe give us a Url so we can check it?
Apologies I read your reply too quickly. I do appreciate your input. I am not sharing the host and the uri only applies on a local network. For some reason the key point is the login. Before logging in, the local js and css files do not load. Afterwards they do load.
No problem, maybe IIS_IUSRS user does not have access to your CSS file?(Security tab) Or maybe your IIS server does not "render" the .css files? Can you log in remote desktop on your server? if you can you should try to load the css from localhost (localhost/Content/Site.css) I'm pretty sure that is a security problem since once you are logged in you can acces it.
I am using IIS 7.5 so I cannot use localhost on the server (I think - I am new to IIS 7+). When I try to navigate to the CSS file via the IP address I get a login screen. This is when I am logged into the web server
My colleague found the answer to that. See stackoverflow.com/questions/2685542/… "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."
4

The answer was to do with assigning permissions to the user IIS_IUSR to the folders in which the application is deployed. A colleague discovered this for me. I have to admit I am not sure why this is necessary but it fixed the problem.

Comments

3

You should explicitly enable anonymous access to the resources you want publicly available. The way to do this is to add a web.config in the folder containing the public content with the following settings:

<configuration>
    <appSettings/>
    <connectionStrings/>
    <system.web>
      <authorization>
        <allow users="*"/>
      </authorization>
    </system.web>
</configuration>

It probably works on the dev server becuase windows authentication means you are not anonymous.

4 Comments

This does not work. I found in Firebug that none of the local files are being loaded, I get the message; Failed to load source for: 192.168.100.999/Content/Site.css
I note that the site.css is defined as a relative path, unlike the other the resources in the head section of the html document. Is firebug loading those resources (eg jquery.Validate.js) okay? Try and change the location defintion for the site.css link to use the @Url.Content helper.
Also, what Http code do you get when the file can't load - ie are you not able to load the files because they do not exist (deployment issue) 404 error, security exception 401 or server error 500?
I do not get any of those codes. In Firebug I get the message; Failed to load source for: 192.168.100.999/Content/Site.css In fact I get this for all the local files.
3

You need to simply change your application pool identity property. It is under advanced settings --> Identity. Change identity value to "ApplicationPoolIdentity" from the drop down. It should fix the issue.

The reason here is that you are not logged in while accessing contents of the website e.g. style sheet or script. So site is not loading those contents. If you are authenticated, it will load all the contents. The identity value is usually Network service or local service.

Comments

3

this is a permission issue: Please add BOTH: IIS_USR and IUSR permissions to the folder structure

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.