简体   繁体   English

保护未定义成员角色的Web文件夹

[英]Securing a web folder with out membership roles defined

Our site is hosted on a shared server. 我们的网站托管在共享服务器上。 We have a login module independent of any membership roles. 我们有一个独立于任何成员角色的登录模块。 We have not used this feature.Our login db table only has email id and pwd fields. 我们尚未使用此功能。我们的登录数据库表仅包含电子邮件ID和pwd字段。 One of our folders (General) contains sensitive documents: pdf; 我们的其中一个文件夹(常规)包含敏感文件:pdf; jpg; jpg; doc files etc. We do not want this folder to be accessed by unauthorized users as well as any search engines such as google, yahoo and others. doc文件等。我们不希望未经授权的用户以及任何搜索引擎(例如google,yahoo等)都可以访问此文件夹。 We added the below lines in the web config 我们在网络配置中添加了以下几行

<location path="General" allowOverride="true">
<system.web>
  <authorization>
    <allow roles="Administrators" />
    <deny users="*" />
  </authorization>
</system.web>
   </location>

This change in web config has secured the folder as accessing the folder results in permission denied message etc. However, now we want our logged in users to be able to access this folder. Web配置中的此更改已保护该文件夹,因为访问该文件夹会导致权限拒绝消息等。但是,现在,我们希望已登录的用户能够访问此文件夹。 We tried adding the below line for logged in users: Roles.CreateRole("Administrators"); 我们尝试为登录的用户添加以下行:Roles.CreateRole(“ Administrators”); However, this is resulting in an error ; 但是,这会导致错误; and it seems asp.net is trying to create membership table and is unable to. 似乎asp.net试图创建成员资格表,但无法这样做。 Is it possible to forcibly assign a Role to a user by completely ignoring the Membership part? 是否可以通过完全忽略成员资格部分来强制将角色分配给用户?

We are not using sqlaspent tables and no plans to use it. 我们没有使用方形表,也没有使用它的计划。 We are also not using ASP.NET Membership framework. 我们也没有使用ASP.NET成员资格框架。

Original question reframed: ( allow roles="Administrators" line removed from web config) 重新构架原始问题:(从Web配置中删除了allow role =“ Administrators”行)

<location path="General" allowOverride="true">
    <system.web>
      <authorization>
              <deny users="*" />
      </authorization>
    </system.web>
       </location>

The above changes in web config results in Access Denied for all files in General folder. Web配置中的上述更改导致“常规”文件夹中所有文件的“访问被拒绝”。 Is it possible to (1) modify web config during run time and change deny users to allow users in say general/test.aspx page load section or (2) load a different web config from a different folder in general/test.aspx page load? 是否可以(1)在运行时修改Web配置并更改拒绝用户以允许用户进入general / test.aspx页面加载部分,或者(2)从general / test.aspx页面的不同文件夹加载不同的Web配置加载?

It sounds like a database connection issue. 听起来像是数据库连接问题。 Your remote provider allows connections to your DB remotely? 您的远程提供者是否允许远程连接到数据库? Can you connect to it using SQL Server Management Studio? 您可以使用SQL Server Management Studio连接到它吗?

Some shared hosting providers don't allow remote access to SQL Servers. 一些共享的托管服务提供商不允许远程访问SQL Server。

have you installed into database the sqlaspent tables? 您是否已将方形表安装到数据库中?

If not yo need to using Aspnet SQl Server Registration Tool , create the correct structure table into database(which roles has been stored). 如果不需要使用Aspnet SQl服务器注册工具 ,请在数据库(已存储角色)中创建正确的结构表。

Create a membershipuser like an administrator, Jojom,Angelina Jolie or what you prefer with it's own property) Create default roles (customer,administrator etc) 创建一个成员身份用户,例如管理员,Jojom,Angelina Jolie或您希望通过其拥有的属性)创建默认角色(客户,管理员等)

bind user to membership and then you will able to use authorization rules. 将用户绑定到成员身份,然后您就可以使用授权规则。

your method say only to aspnet that only administrator member which are visibile via Context.User.IsInRole("Administrator") can access to this page ....but to be an administrator you need to be stored into a database or in a custom provider...... 您的方法仅对aspnet说,只有通过Context.User.IsInRole(“ Administrator”)访问的管理员成员才能访问此页面....但是要成为管理员,您需要将其存储到数据库或自定义中提供者...

I don't know a way assigning a Role to a user without using a membership provider. 我不知道在不使用成员资格提供程序的情况下将角色分配给用户的方法。 One thing I can think of, is giving up the location sector at the web config and start monitoring every request to the application using the Global.asax Application_BeginRequest method and check if the request is to the restricted folder and if the user loged in (session). 我能想到的一件事是,放弃Web配置中的位置扇区,并开始使用Global.asax Application_BeginRequest方法监视对应用程序的每个请求,并检查该请求是否在受限文件夹中以及用户是否登录了(session )。

Another way is to use some kind of httpHandler to do the save thing. 另一种方法是使用某种httpHandler进行保存。

Edit: In your login form, once a user authenticated by his username and password assign a session variable that notes this user is Administartor. 编辑:在您的登录表单中,一旦通过其用户名和密码进行身份验证的用户分配了一个会话变量,该会话变量指出该用户为Administartor。

void Login()
{
    //check user+password
    //...
    if(UserIsAuthenticated)
    {
        Session["Administrator"] = true;
        //more stuff to do with authenticate user
    }
}

and in your Global.asax: 并在您的Global.asax中:

void Application_BeginRequest(object sender, EventArgs e)
{
    if(Request.PhysicalPath.Contains("RestrictedFolderName")//you can do a more profound check here
    {
         if((bool)Session["Administrator"])
             //all ok - do nothing
         else
             //not authorized user trying to access folder- do redirect or somthing 
    }
}

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

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