简体   繁体   English

使用Web.config和会话变量控制网站文件夹访问?

[英]Control Website Folder Access using Web.config and session variable?

the following web.config file is placed in a specific sub-folder on a website. 以下web.config文件放在网站上的特定子文件夹中。 It will allow the user John.Doe to access the pages inside the folder but will deny anonymous users 它将允许用户John.Doe访问文件夹内的页面,但将拒绝匿名用户

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
    <authorization>
        <allow users="John.Doe" />
        <deny users="?" />
    </authorization>
</system.web>
</configuration>

Is it possible to replace users in the following web.config file with certain session variable 是否可以使用某个会话变量替换以下web.config文件中的用户

for example getting the day(sunday, monday, etc) from date and storing it in session("DayVar") then the code should be something like this for the subfolder monday 例如从日期获取日期(星期日,星期一等)并将其存储在会话(“DayVar”)中,那么代码应该是这样的子文件夹星期一

 <?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
    <authorization>
        <allow session("DayVar")="monday" />
        <deny session("DayVar")<>"monday"/>
    </authorization>
</system.web>
</configuration>

is this doable ? 这可行吗?

This is not something that is built into the framework. 这不是构建在框架中的东西。

You could handle this via a custom base page or similar to implement that type of restriction. 您可以通过自定义基页或类似方法处理此问题,以实现此类限制。

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

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