【问题标题】:Restrict Admin Pages to Admin Users only将管理员页面限制为仅管理员用户
【发布时间】:2011-05-24 05:50:46
【问题描述】:

我有一个 ASP.NET 网站。我想将管理文件夹限制为仅在此 SQL Server 表中具有“管理员角色”的用户:tbl_Users_Admin 具有列 UIDPWDNameRoleStatus)。我希望任何用户都可以公开访问其余所有根页面。

我不会使用 ASP.NET Membership。

只为管理员用户提供了 URL (https://www.Website.com/Admin/Login.aspx)。

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

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

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

但是我没有成功解决它。

虽然我尝试在根目录下的 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>

【问题讨论】:

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

标签: c# asp.net sql-server


【解决方案1】:

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

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

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

【讨论】:

  • 谢谢 Akhtar,我会试试你的解决方案。
猜你喜欢
  • 2015-04-12
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多