仅限管理员用户访问管理页面
我有一个 ASP.NET 网站。我想将管理文件夹限制为仅在此 SQL Server 表中具有“管理角色”的用户:tbl_Users_Admin
具有列 UID
、PWD
,名称
,角色
,状态
)。我希望任何用户都可以公开访问其余的所有根页面。
我不会使用 ASP.NET 会员资格。
管理员用户只需获得 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>
I have an ASP.NET Website. I want to restrict the Admin Folder to only users who are of 'Admin Role' in this SQL Server Table: tbl_Users_Admin
having columns UID
, PWD
, Name
, Role
, Status
). The rest of all the root pages I want to be publicly accessible by any user.
I will not be using ASP.NET Membership.
Admin User is just given the URL (https://www.Website.com/Admin/Login.aspx).
I have two Login.aspx pages in the root as well as in the Admin Folder.
I tried to resolve it through the Forms Authentication, but I am unable to resolve it.
Few forums suggested to create two different Web.Config files (one for root folder of website and another for Admin Folder), but it seems to be an inefficient way to me.
But I have not been successful to resolve it otherwise.
Although I have tried to do this using the as follows in the web.config file at root:
<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>
And for the rest of the root pages (Public Pages):
<system.web>
For rest of the root pages (Public Pages)
</system.web>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要在 web.config 中添加 Admin 文件夹。
只需在
configuration
部分下的web.config
中添加以下内容即可。You don't need to add the Admin folder in the web.config.
Just add the following in the
web.config
under theconfiguration
section.