Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
971 views
in Technique[技术] by (71.8m points)

asp.net - Deny access to html page

I have ASP.NET Web Forms project. I created a folder Demo in this project and put in this folder HelloWorld.html. I need deny access to this html (it's important not asp) page for all users. How can I do this?

I tried this way, but it didn't work (but it works perfectly with asp page).

<configuration>
    <location path="Demo/HelloWorld.html">
        <system.web>
            <authorization>
                <deny users="*"/>
            </authorization>
        </system.web>
    </location>
</configuration>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your web.config is correct. The problem is this secures files that are going through the ASP.NET pipeline. Certain static files, like html files, are served up directly by IIS and so it is bypassing your security.

You can force static files to go through the ASP.NET pipeline by adding a handler for them under the <system.webServer> section of your web.config:

<handlers>
    <add name="HTMLHandler" type="System.Web.StaticFileHandler" path="*.html" verb="GET"  />
</handlers>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...