mikedopp.net

doppNet
posts - 56, comments - 8, trackbacks - 1

Redirect Roles to specific pages

I have been looking for a better way to handle redirects but this works very well.

 1: <%@ Page Language="C#" %>
 2: <%@ Import Namespace="System.Security" %>
 3: <script runat="server">
 4:  
 5:  void Page_Load()
 6:  {
 7:  if(Roles.IsUserInRole("Admin"))
 8:  {
 9:  Response.Redirect("~/members/admin/default.aspx");
 10:  }
 11:  else if (Roles.IsUserInRole("Member"))
 12:  {
 13:  Response.Redirect("~/members/users/default.aspx");
 14:  }
 15:  else
 16:  {
 17:  Response.Redirect("~/default.aspx");
 18:  }
 19:  }
 20:  
 21: </script> 

If you want to display an access denied page just change the default.aspx to:

 1:  Else
 2: Response.Redirect ("~/AccessDenied.aspx")
Enjoy!!!

Print | posted on Wednesday, August 01, 2007 6:00 AM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 1 and 1 and type the answer here:

Powered by: