在表单身份验证中何处提及 Accessdenied 页面
我已经实现了表单身份验证,
<location path="Admin">
<system.web>
<authorization>
<deny users="?"/>
<allow roles="Admin" />
<deny roles="systemAdmin"/>
</authorization>
</system.web>
</location>
因为在上述权限中,管理员可以访问管理文件夹,而系统管理员则不能访问。
我已经制作了自定义 Accessdenied 页面,向用户显示消息,他无权访问此页面
现在的问题是,如果 systemAdmin 尝试点击 Admin 文件夹页面,他将被重定向到 AccessDenied.apsx 页面。 (请注意:两个用户都经过身份验证,1 个用户有权访问某个文件夹,其他用户有权访问其他文件夹。我不想在每个页面中进行检查)在
哪里指定 accessdenied 页面重定向?
谢谢
I have implement Form Authentication
<location path="Admin">
<system.web>
<authorization>
<deny users="?"/>
<allow roles="Admin" />
<deny roles="systemAdmin"/>
</authorization>
</system.web>
</location>
Since in above mentioned rights, Admin can have access to Admin folder and systemAdmin can't have.
I have make custom Accessdenied page where I am showing message to user he has not permission to access this page
Now the issue is, If systemAdmin try to hit Admin folder page, he will be redirected to AccessDenied.apsx page. (please Note: both user are authenticated, 1 user have permission to some folder and other user have permission to other folder. I don't want to put check in each page)
where to specify accessdenied page redirection ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遗憾的是,默认访问机制不区分 401 Unauthorized 和 403 Forbidden。
如果您不想实施Saar的解决方案 使用通用基页面 - 并让所有管理页面继承基页面类,另一种选择是在登录页面中编写逻辑 - 检查用户是否已经登录(
Request.IsAuthenticated
)并显示一条消息,指出他们没有查看页面的权限。您可能还应该将
Response.StatusCode
更改为 403,将Response.StatusMessage
更改为"Forbidden"
Sadly the default access mechanisms don't differentiate between between a 401 Unauthorized and a 403 Forbidden.
If you don't want to implement Saar's solution of using a common base page - and have all your admin pages inherit from the base page class, an alternative option would be to write the logic in your login page - check to see if the user is already logged in (
Request.IsAuthenticated
) and display a message stating that they don't have permission to view the pages.You should probably also change the
Response.StatusCode
to 403 and theResponse.StatusMessage
to"Forbidden"
我没有在 web.config 中看到重定向到 AccessDenied 页面的选项。
我在公共基页中使用以下代码。
更新:
我只是玩了一下
通过上述设置,如果systemAdmin访问管理页面,他将被重定向到登录页面。您可以在那里放置一些逻辑,如果用户已经登录,则重定向到访问被拒绝的页面。
让我知道这是否对您有帮助。
I haven't seen in option to redirect to AccessDenied page in web.config.
I am using following code in common base page.
update:
I just played around little bit
With above settings, if systemAdmin visits admin pages, he will get redirected to login page. There you can put some logic, if user already logged in, then redirect to access denied page.
Let me know if this helps you or not.