Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
973 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...