仅将管理员页面限制为管理员用户

时间:2011-05-24 05:50:46

标签: c# asp.net sql-server

我有一个ASP.NET网站,在此我想将管理文件夹限制为仅在SQL Server表中具有“管理员角色”的用户(tbl_Users_Admin,其列为UID,PWD,名称,角色,状态) 。我希望任何用户公开访问的所有根页面的其余部分。

我不会使用ASP.NET Membership。

Admin User刚刚获得了URL(www.Website.com/Admin/Login.aspx)。

我在根目录和管理文件夹中有两个Login.aspx页面。

我尝试通过表单身份验证解决它,但我无法解决它。

很少有论坛建议创建两个不同的Web.Config文件(一个用于网站的根文件夹,另一个用于管理文件夹),但它似乎对我来说效率低下。

但我没有成功解决它。

虽然我尝试使用root中的web.config文件中的以下内容执行此操作:

  <location path="Admin">
  <system.web>
<authentication mode="Forms">
      <forms loginUrl="/Admin/Login.aspx" name=".ASPXFORMSAUTH" defaultUrl="/Admin/Login.aspx" >
      </forms>
    </authentication>
    <authorization>
    <allow roles="administrators" />
      <allow users="admin" />
      <deny users="?" />
    </authorization> 
    <sessionState mode="InProc" cookieless="false"  timeout="20">
    </sessionState>
    <customErrors defaultRedirect="~/Admin/ErrorPages/Error.aspx" mode="On">
      <error statusCode="404" redirect="~/Admin/ErrorPages/Error.aspx" />
    </customErrors>
    <compilation debug="true">
         <codeSubDirectories>
          <add directoryName="CSharp"/>
          <add directoryName="VB"/>
        </codeSubDirectories>
     </compilation>
    </system.web>
  </location>

对于其余的根页(公共页面):

<system.web>
    For rest of the root pages (Public Pages)
</system.web>

1 个答案:

答案 0 :(得分:1)

您无需在web.config中添加Admin文件夹。

只需在web.config部分下的configuration添加以下内容即可。

<location path="Admin">
    <system.web>
        <authorization>
            <deny users="?"/>
            <allow roles="Admin"/>
            <deny users="*"/>
        </authorization>
    </system.web>
</location>
相关问题