简体   繁体   English

如何在ASP.NET网站中写入页面白名单

[英]How to write a page whitelist in an asp.net website

I have a website and as one of security options (prevent path traversal) I am planning to use a white list of pages which can be accessed. 我有一个网站,并且作为一种安全选择(防止遍历路径),我计划使用一个可以访问的白名单。 But my problem is I don't know how to do it. 但是我的问题是我不知道该怎么做。 Can you share some articles or simple of code how to create a white list? 您可以分享一些文章或简单的代码来创建白名单吗?

如果我正确理解了这个问题,则希望允许某些用户访问您网站上的某些页面-您是否考虑过ASP.NET安全修整?

How many pages does the site have? 该网站有多少页? If there are not too many pages and if pages are not added/removed frequently you can manually create a list of pages. 如果页面太多,并且不经常添加/删除页面,则可以手动创建页面列表。 If you are using master pages you can set this up in Page_Load method. 如果使用母版页,则可以在Page_Load方法中进行设置。

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Dictionary<string,string> allowedUrls = LoadAllowedURLs();

            if (!allowedUrls.ContainsKey(Request.Path))
            {
                Response.Redirect("Some_default_redirect_page.aspx");   
            }
        }

    }

Now, if you do have a lot of pages you would need more sophisticated solution that uses web.config and more… 现在,如果您确实有很多页面,则需要使用web.config的更复杂的解决方案以及更多…

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM