IIS错误404甚至文件存在,aspx正常打开

时间:2018-05-03 18:15:34

标签: c# asp.net iis web-config

我无法访问html页面或任何图像文件,只有我能够访问成功的.apsx asmx和ashx文件。我收到 404 - 找不到文件或目录

例如:

mysite.com/index.html  ( getting 404 error)
mysite.com/image.jpg( getting 404 error)

mysite.com/page.aspx (working fine)
mysite.com/service.asmx/method  ( working fine)

我试图做的事情:

  1. 检查IUSR和IIS_IUSRS的文件夹权限。
  2. MIME类型
  3. 映射处理程序
  4. 我将发布我的web.config设置。

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.web.extensions>
        <scripting>
          <webServices>
            <jsonSerialization maxJsonLength="50000000" />
          </webServices>
        </scripting>
      </system.web.extensions>
      <system.web>
        <customErrors mode="Off" />
        <compilation debug="true" />
        <authentication mode="None" />
        <webServices>
          <protocols>
            <add name="HttpGet" />
            <add name="HttpPost" />
          </protocols>
        </webServices>
      </system.web>
      <system.webServer>
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
            <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
          </customHeaders>
        </httpProtocol>
        <validation validateIntegratedModeConfiguration="false" />
        <modules runAllManagedModulesForAllRequests="true" />
        <handlers>
          <remove name="ScriptHandlerFactory" />
          <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          <add name="PHP5" path="*.php" verb="*" modules="CgiModule" scriptProcessor="C:\******\php-cgi.exe" resourceType="Unspecified" requireAccess="Script" />
          <add name="uploadfile" path="uploadfile.ashx" verb="*" type="Namespace.uploadfile" />
        </handlers>
      </system.webServer>
      <connectionStrings>
        <add name="SalikConnection" connectionString="Data Source=**************;Initial Catalog=*****;uid=*****;password=****************;" providerName="System.Data.SqlClient" />
      </connectionStrings>
    </configuration>
    

    有什么建议吗?

    已编辑&amp;解决

    将静态内容添加到web.config

     <system.webServer>
            <handlers>
               <clear />
                <add 
                    name="StaticFile" 
                    path="*" verb="*" 
                    modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" 
                    resourceType="Either" 
                    requireAccess="Read" />
            </handlers>
            <staticContent>
                <mimeMap fileExtension=".*" mimeType="application/octet-stream" />
            </staticContent>
    

1 个答案:

答案 0 :(得分:0)

请确保在Windows功能对话框中的IIS下选中了“静态内容”复选框。检查屏幕截图

Static Content