简体   繁体   中英

IIS express doesn't serve portable network graphics

My Situation

I have built an website using ASP.NET MVC 5. The website is running on an IIS express (Windows 8). I have basic knowledge in webdevelopment, but I cannot figure out how to solve my problem.

The Problem

My IIS express doesn't serve my portable network graphics as expected. I am always seeing the default 404 page of the IIS express with the following default description:

HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 

First attempt

I tried to narrow down the problem by adding following code to my Global.asax.cs file. The request should only be processed, if the requested file is available. But the requested png is always available...

Global.asax.cs (Snippet)

public override void Application_BeginRequest(object sender, System.EventArgs e)
{
  if (System.IO.File.Exists(System.Web.HttpContext.Current.Request.PhysicalPath))
    base.Application_BeginRequest(sender, e); 
}

Second attempt

Because I thought it would be possible that my [IIS doesn't know][1] the MIME-Type of Portable Network Graphics, I ended up adding the static file handlers in my Web.Config:

web.config (Snippet)

  <add name="StaticFileTS"  verb="GET,HEAD" path="*.ts"  type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileMap" verb="GET,HEAD" path="*.map" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileCss" verb="GET,HEAD" path="*.css" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileJs"  verb="GET,HEAD" path="*.js"  type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFilePng" verb="GET,HEAD" path="*.png" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileJpg" verb="GET,HEAD" path="*.jpg" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileGif" verb="GET,HEAD" path="*.gif" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />
  <add name="StaticFileIco" verb="GET,HEAD" path="*.ico" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc" />

Can you please give me some idea, what I have forgotten? Do you need additional information?

Thanks :)

Update #1

The URL I want to call is:
http://localhost:60809/Merkliste/Images/Icons/ButtonBar/ButtonBarInclude/Download_All.png

The physical file path is:
C:\\softdev\\Projectname\\Areas\\Merkliste\\Images\\Icons\\ButtonBar\\ButtonBarInclude\\Download_All.png

I already tried to set the build action of my image to "embedded ressource" instead of "content" .

In your web.config try adding the mime type like this:

<system.webServer>
  ...
  <staticContent>
    <mimeMap fileExtension=".png" mimeType="image/png" />
  </staticContent>
</system.webServer>

I would also investigate using fiddler to see the exact http request, it could be to do with your markup or css.

尝试将文件包含在VS项目中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM