2012-03-25 86 views
0

我使用这个代码在web.config中限制特定文件夹中的角色与web.config中

<authentication mode="Forms"> 
     <forms timeout="2000" name="A" loginUrl="login.aspx" protection="None" path="/"></forms> 
    </authentication> 

认证和每个文件夹中使用的web.config

<?xml version="1.0"?> 
<configuration> 
    <system.web> 
     <authorization> 
     <allow roles="Admin"/> // or other roles in different pages 
     </authorization> 
    </system.web> 
</configuration> 

当用户不Admin Role想要打开此页面,自动重定向到“login.aspx”

是否有可能重定向到其他页面,如“access-denied.aspx”

回答

0

试试这个,让我知道会发生什么?

<system.web> 
     <authorization> 
     <allow roles="Admin"/> // or other roles in different pages 
     <deny users ="*" /> 
     </authorization> 
</system.web> 

添加以下代码到登录页面:

if (!IsPostBack) 
{ 
    if (User.Identity.IsAuthenticated) 
    { 
      if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"])) 
      { 
       Response.Redirect("~/Admin/AccessDenied.aspx"); 
      } 
    } 

} 
+0

谢谢Praneeth,但我想处理这个问题,不使用代码, – Mironline 2012-03-25 17:28:27

相关问题