找不到IIS Express静态文件

时间:2018-11-27 12:11:11

标签: asp.net iis iis-express

请允许我说我有Linux背景,并且在Windows上进行开发对我来说还很新。

我正在处理在Visual Studio中打开的ASP.NET项目。该项目最初设置为通过IIS运行。 VS很有帮助地问我是否要尝试IIS Express,我说可以。该应用程序最初有一些小问题,但这是因为代码既旧又庞大。解决这些问题后,应用程序可以正常加载,但所有静态文件除外。对于文件系统上实际存在的资源,我得到404 Not Found。

您在照片中看到的物理路径位于Web.config文件旁边的文件夹中。我可以从exec目录(它是图形目录的同级目录)中加载aspx文件。我要在此图片中加载的favicon.ico文件位于图形目录中。

我今天已经阅读了很多有关IIS和IIS express的文档,但它们都没有提到必须对静态文件做一些特殊的事情。也许我只是厚。如果需要我的Web.config,请告诉我,我可以在这里附加它。

IIS Express Error page

编辑:

1)在此方面取得了一些进展。在成熟的IIS下,我也得到了完全相同的错误。我的静态内容没有显示。

2)这是所请求的web.config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
  </configSections>
  <!--
    For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.

    The following attributes can be set on the <httpRuntime> tag.
      <system.Web>
        <httpRuntime targetFramework="4.5" />
      </system.Web>
  -->
  <loggingConfiguration name="loggingConfiguration" tracingEnabled="true" defaultCategory="General">
    <listeners>
      <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" source="Enterprise Library Logging" formatter="Text Formatter" log="" machineName="." traceOutputOptions="DateTime, Timestamp, ProcessId" />
      <add name="W3C Rolling Flat File Trace Listener" type="App.W3CLogTraceListener, App, Version=1.0.0.0, Culture=neutral" listenerDataType="App.W3CLogTraceListenerData, App, Version=0.0.0.0, Culture=neutral" fileName="appA65.log" fileHeader="date time session-id client-ip page url form-data cookie" footer="" formatter="Text Formatter" header="" rollInterval="Midnight" timeStampPattern="yyyy-MM-dd" />
    </listeners>
    <formatters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" template="{message}" name="Text Formatter" />
    </formatters>
    <logFilters>
      <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Filters.LogEnabledFilter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" enabled="false" name="Logging Enabled Filter" />
    </logFilters>
    <categorySources>
      <add switchValue="All" name="General">
        <listeners>
          <add name="W3C Rolling Flat File Trace Listener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="All" name="Logging Errors &amp; Warnings">
        <listeners>
          <add name="Event Log Listener" />
        </listeners>
      </errors>
    </specialSources>
  </loggingConfiguration>
  <appSettings>
    <!-- To enable or disable IETP user session management, true to enable, false to disable -->
    <add key="IetpSessionEnabled" value="false" />
    <!-- To specifies where the folder for session files -->
    <add key="IetpUserSessionServerPath" value="d:\apps\ietpusersessions" />
    <!-- To determines the duration of s user session in terms of minutes -->
    <add key="IetpUserSessionLengthInMinutes" value="600" />
    <!-- to enable/disable sending out email on exceptions, true to enable, false to disable -->
    <add key="EmailAlertEnabled" value="true" />
    <!-- the exception email alert list, seperated by comma -->
    <add key="EmailAlertToAddress" value="alice@example.com" />
    <!-- email sender address -->
    <add key="EmailAlertFromAddress" value="bob@example.com" />
    <!-- to enable or disable Pdf print, wehn set "true", all user local print requests will be -->
    <!-- processed on the server and the final PDF will be rended in browser -->
    <add key="PdfPrintEnabled" value="true" />
    <add key="PdfPrintServiceUrl" value="https://example.com/PdfPrintService/PdfPrintService/PDFPrint.aspx" />
    <add key="FooterDisclaimer" value="Footer here" />
  </appSettings>
  <system.web>
    <httpRuntime targetFramework="4.0" requestValidationMode="2.0" />
    <!-- <httpRuntime executionTimeout="300" /> -->
    <compilation debug="true" defaultLanguage="c#" targetFramework="4.5.1" />
    <customErrors defaultRedirect="~/exec/generalError.aspx" mode="Off" />
    <sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" stateNetworkTimeout="11" timeout="600" />
    <pages controlRenderingCompatibilityVersion="4.0" />
  </system.web>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <remove name="URLWriteHttpModule" />
      <add name="URLWriteHttpModule" type="App.URLWriteHttpModule" />
    </modules>
    <defaultDocument>
      <files>
        <clear />
        <add value="default.aspx" />
        <add value="Default.asp" />
        <add value="Default.htm" />
        <add value="index.htm" />
        <add value="index.html" />
      </files>
    </defaultDocument>
    <tracing>
      <traceFailedRequests>
        <add path="*">
          <traceAreas>
            <add provider="ASP" verbosity="Verbose" />
            <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
            <add provider="ISAPI Extension" verbosity="Verbose" />
            <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
          </traceAreas>
          <failureDefinitions timeTaken="00:00:00" statusCodes="500-599" verbosity="Error" />
        </add>
      </traceFailedRequests>
    </tracing>
        <handlers accessPolicy="Read, Execute, Script" />
  </system.webServer>
</configuration>

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

您可以尝试添加吗?

<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>

IIS Pre conditions

您是否在IIS中启用了静态内容?

enter image description here

  1. 检查您的gloabl.asax这种行是否存在

    routes.IgnoreRoute(“ {resource} .axd / {* pathInfo}”);要么 route.IgnoreRoute(“ { favicon}”,新的{favicon = @“(。 /)?favicon.ico(/.*)?"});

或类似的东西

  1. 注释URL重写部分并检查其工作情况吗?

而且我相信您要仔细检查文件是否存在或是否在正确的路径中:)

答案 2 :(得分:0)

检查您的静态内容是否通过MSBuild发布。如果没有,请将这些行添加到您的.csproj文件中:

<ItemGroup>
    <Content Include="graphics\**\*.*" />
</ItemGroup>