ASP.NET重定向未经授权的用户默认/登录页面 [英] ASP.NET redirect unauthorised user to default/login page

查看:108
本文介绍了ASP.NET重定向未经授权的用户默认/登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个simpe网站,不同级别的访问。我已经使用了asp.net配置的安全功能来创建用户和角色。登录作品,注销的作品,获得了正确的网页被授予人以合适的角色。

I have a simpe website with different levels of access. I have used the asp.net configuration security feature to create users and roles. Login works, logout works, access to the right pages is granted to people with the right role.

不过,我努力寻找一种方法来重定向人谁没有合适的角色还是在当他们尝试访问受限制的内容不被记录。

However, i am struggling to find a way to redirect people who are not in the right role or are not logged in when they try to access restricted content.

我怎样才能重定向,而不​​是刚刚起步的404错误页面?

How can I redirect instead of just getting the 404 error page?

非常感谢

推荐答案

默认情况下窗体身份验证用户的网页重定向名为的login.aspx 时,他/她试图访问受限制的资源的人,他/她目前还没有权限。所以,如果你没有在的login.aspx 未找到资源错误( HTTP 404 )将被抛出。 为了克服这个创建的login.aspx 页面或告诉asp.net使用另一个页面(yourloginpage.aspx)作为登录页面。做你应该在&LT定义它后者;形式GT; 在你的web.config的建议通过 sathishkumar印标记

By default forms authentication redirects the user to a page with the name login.aspx when he/she tries to access a restricted resource to whom he/she currently has no permission. So if you don't have the login.aspx the resource not found error(HTTP 404) will be thrown. To overcome this create the login.aspx page or tell asp.net to use another page(yourloginpage.aspx) as the login page. To do the latter you should define it in the <forms> tag in your web.config as suggested by sathishkumar indian

  <authentication mode="Forms">
    <forms loginUrl="yourloginPage.aspx" />
 </authentication>

这篇关于ASP.NET重定向未经授权的用户默认/登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆