IT박스

IIS에서 CSS, 이미지, JS가로드되지 않음

itboxs 2020. 7. 24. 07:55
반응형

IIS에서 CSS, 이미지, JS가로드되지 않음


내 모든 응용 프로그램은 정상적으로 작동했지만 IIS의 모든 사이트가 CSS, 이미지, 스크립트를로드하지 않습니다. 로그인 페이지로 리디렉션됩니다.

로그인하면 정상적으로 작동합니다. 예 : mysite.com/Account/LogOn?ReturnUrl=%2fpublic%2fimages%2ficons%2f41.png

내 로컬 컴퓨터에서 로그인하지 않고도 정상적으로 작동합니다.


문제는 IIS가 정적 콘텐츠를 제공하지 않아서 설정할 수 있다는 것입니다. 여기에 이미지 설명을 입력하십시오

출처 : http://adilmughal.com/blog/2011/11/iis-7-not-loading-css-and-image/

윈도우 10:

위 대화 상자의 Windows 10 버전


Windows Server 2012 R2의 IIS 8.5에서 ASP.Net 4.5에 웹 응용 프로그램을 설치할 때 인증되지 않은 페이지에서 CSS, JS 및 이미지를로드하지 못하는 경우에도 같은 문제가있었습니다.

  1. 정적 콘텐츠 역할을 설치했습니다
  2. 내 웹 응용 프로그램은 IIS의 wwwroot 폴더에 있었고 모든 Windows 폴더 권한이 그대로 유지되었습니다 (IIS_IUSRS를 포함한 기본 권한).
  3. CSS, JS 및 이미지가 포함 된 모든 폴더에 대한 권한을 추가했습니다.
  4. Windows 공유에 웹 응용 프로그램 폴더가 있으므로 @ imran-rashid가 제안한 공유를 제거했습니다.

그러나 아무것도 문제를 해결하지 못한 것 같습니다. 그런 다음 익명 사용자의 ID를 App Pool Identity로 설정하려고 시도하고 작동하기 시작했습니다.

인증 기능을 클릭하십시오 익명 인증 편집 앱 풀 ID로 변경

몇 시간 동안 고개를 저으며이 응답이 동료 개발자의 고통을 덜어주기를 바랍니다.

왜 이것이 효과가 있는지 알고 싶습니다. 이견있는 사람?


비슷한 오류가 발생했습니다. 콘솔은 다음과 같습니다.

오류

내 문제는 회사가 하나의 최상위 도메인을 사용하고 하위 도메인을 사용하지 않았기 때문에 하위 폴더에서 내 사이트를 실행하고 있다는 것입니다. 이처럼 :

host.com/app1

host.com/app2

My code looked like this for including scripts which worked fine on localhost but not in app1 or app2:

<link rel="stylesheet" type="text/css" href="/Content/css/font-awesome.min.css" />

Added a tilde sign ~ to src and then everything worked:

<link rel="stylesheet" type="text/css" href="~/Content/css/font-awesome.min.css" />

Explanation of ~ vs /:

  • / - Site root
  • ~/ - Root directory of the application

/ will return the root of the site (http://host.com/),

~/ will return the root of the application (http://host.com/app1/).


Try removing the staticContent section from your web.config.

<system.webServer>
    <staticContent>
        ...
    </staticContent>
</system.webServer>

This might not answer your question but I've been banging my head with the same symptoms with a new IIS installation. CSS, JS and images were not showing up. Was due to the "Static Content" role not being installed in IIS 7.5.


You probably have Windows authentication enabled in your web.config. On a local machine, your Windows credentials are automatically passed and it works. On a live site, you are treated as an anonymous user (IE setting can control this, but don't modify this unless you really know what you are doing).

This causes the following:

  • You are required to explicitly login.
  • Resources like scripts and CSS are not served on the login page because you are not authenticated.

This isn't broken, just working as intended, but to "fix" this:

  • Change the authentication type in the web.config if you don't want any login.
  • And/or add a web.config in the directory(s) containing CSS, images, scripts, etc. which specifies authorization rules.

Add this to your web.config

<location path="Images">
    <system.web>
        <authorization>
            <allow users="*" />
        </authorization>
    </system.web>
</location>

It was windows permission issue i move the folder thats it inherit wrong permissions. When i move to wwwroot folder and add permission to iis user it start working fine.


Use this in configuration section of your web.config file:

<location path="images">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>
</location>
<location path="css">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>
</location>
<location path="js">
<system.web>
  <authorization>
    <allow users="*"/>
  </authorization>
</system.web>
</location>

For me adding this in the web.config resolved the problem

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" >
      <remove name="UrlRoutingModule"/>    
    </modules>
</system.webServer>

My hour of pain was due to defining MIME types in the web.config. I needed this for the development server but local IIS hated it because it duplicated MIME types... once I removed these from the web.config the problem with js, css, and images not loading went away.


In my case,

IIS can load everything with localhost, but could not load my template files app.tag from 192.168.0.123

because the .tag extension was not in the list.

IIS MIME 유형


To fix this:

Go to Internet Information Service (IIS)

Click on your website you are trying to load image on

Under IIS section, Open the Authentication menu and Enable Windows Authentication as well.


One suggestion I have found helpful in the past when developing sites in localhost test environment when working with a copy of production site. Make sure that you comment out the canonical tags:

  <!--<base href="http://www.example.com/">//-->

If you tried all the above solutions and still have problems, consider using the method ResolveClientUrl() of ASP.NET .

A script for Example :

Instead of using

<script src="~/dist/js/app.min.js" ></script>

Use the method

<script src="<%= ResolveClientUrl("~/dist/js/app.min.js") %>" ></script>

This was my solution that worked for a friend I was helping!


I had this same problem. For me, it was due to Cache-Control header being set at the server level in IIS to no-cache, no-store. So for my application I had to add in the below to my web.config:

<httpProtocol>
    <customHeaders>
        <remove name="Cache-Control" />
    </customHeaders>
</httpProtocol>

그 원인 중 하나는 응용 프로그램이 포트 443 (표준 SSL 포트)에서 실행될 것으로 예상하고 포트 443이 이미 사용 중이기 때문입니다. Skype가 컴퓨터에서 실행되는 동안 개발자가 응용 프로그램을 실행하려고 시도 하면서이 문제가 여러 번 발생했습니다.

놀랍게도 Skype는 포트 443에서 실행됩니다. 이것은 제 생각에는 끔찍한 디자인 결함입니다. 응용 프로그램이 443 대신 444에서 실행하려고하면 Skype를 종료하면 문제가 해결됩니다.


나는 추가 app.UseStaticFiles();가 고정되는 것보다, 구성 방법의 starup.cs에이 코드를.

이 폴더에 대한 권한을 확인하십시오.


이미지 사용

@Url.Content("~/assets/bg4.jpg")

스타일에 이것을 사용하십시오

style="background-image:url(@Url.Content("~/assets/bg4.jpg"))

참고 URL : https://stackoverflow.com/questions/10512053/css-images-js-not-loading-in-iis

반응형