HTTP Error 404.7 - Not Found The request filtering

2019-01-18 04:14发布

问题:

I'm trying to configure the default webpage for an IIS 7.5 website.

Request filtering is turned on. However .aspx pages are allowed, I've set default.aspx to be the default page for the website.

If I browse to localhost/default.aspx I get a webpage as expected.

IF I browse to localhost/ I get

HTTP Error 404.7 - Not Found The request filtering module is configured to deny the file extension.

Any ideas?

回答1:

It looks like the request filtering is actually filtering for a blank file name. Therefore you have to add this to the request filtering block in the web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions allowUnlisted="true">
          <remove fileExtension="." />
          <add fileExtension="." allowed="true" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

It's obvious now, but really I think its a massive gotcha.


More info: IIS 7 Not Serving Files - 404.7 Error



回答2:

You can resolve this by adding the file extension into the request filtering module of IIS.



回答3:

You can resolve by adding:

<requestFiltering>
    <fileExtensions allowUnlisted="true">
        <remove fileExtension="." />
        <add fileExtension="." allowed="true" />
    </fileExtensions>
</requestFiltering>

to your Web.Config file



回答4:

Be sure to remove any PostBackURL="MyPage.aspx" from the button on the page. My guess is that when the postbackurl is included, IIS thinks its getting the page as a file. It rejects the .aspx file type by default. You can see this in the page error.

Bad: Creates a 404.7 (notice the PostBackURL)

<asp:FileUpload runat="server"  ID="uplReplaceFile" ToolTip="Update this file" />

 <asp:Button runat="server" PostBackUrl="MyPage.ascx"  ID="bnHiddenFileUploadListener" OnClick="bnHiddenFileUploadListener_OnClick" />

Good: No error

<asp:FileUpload runat="server"  ID="uplReplaceFile" ToolTip="Update this file" />

 <asp:Button runat="server" ID="bnHiddenFileUploadListener" OnClick="bnHiddenFileUploadListener_OnClick" />