且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从ASP.NET中浏览网页的限制未记录/未经授权的用户

更新时间:2023-12-01 15:22:58

先建立成员身份和角色提供。有关于它的整个故事。我会在这里给一个帮助。

First establish membership and role provider. There is whole story about it. I will give a help here.

下面是链接的SqlMembershipProvider(你可以把选项之一):
http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx

Here is link to SqlMembershipProvider (one of the options you can take): http://msdn.microsoft.com/en-us/library/system.web.security.sqlmembershipprovider.aspx

下面是链接SqlRoleProvider(您可以采取的选项重新只有一个)::
http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider.aspx

Here is link to SqlRoleProvider (again only one of the options you can take):: http://msdn.microsoft.com/en-us/library/system.web.security.sqlroleprovider.aspx

您已经建立之后,你可以限制在文件夹级别的用户/角色的访问。将这个code到web.config文件(配置标签中):

After you have established this you can limit user/role access on folder level. Put this code to web.config (inside configuration tag):

  <location path="AdminPages">
    <system.web>
      <authorization>
        <allow roles="Administrator"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="UserPages">
    <system.web>
      <authorization>
        <allow roles="Administrator,User"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>

下面一点交代。根文件夹AdminPages将alowed只在角色管理员的用户。根文件夹UserPages中的角色管理员和用户的用户。在这两种情况下是未知的用户将不会被允许访问的文件夹。这是你所需要的。替代这是创建类,从页继承,然后有处理页面访问......不过我不会走那条路。

Here is little explaination. Root folder "AdminPages" will be alowed only to users in role "Administrators". Root folder "UserPages" to users in role "Administrator" and "User". In both cases unknown users will not be allowed to access folders. This is all you need. Alternative to this is to create class that inherits from Page and then there handle page access... however I would not go that way.