views:

501

answers:

3

I was wondering if anyone knows a proper/best practice way of overriding the url of where the page takes you after you successfully login.

I tried this:

   protected void Login1_LoggedIn(object sender, EventArgs e)
        {
           if (Roles.IsUserInRole(Login1.UserName, "Other"))
            {
                Response.Redirect("/User/");
            }
            else if (Roles.IsUserInRole(Login1.UserName, "Administrator"))
            {
                Response.Redirect("/Admin/");

            }
        }

Does anyone have any other suggestions?

A: 

What I do is send them to a page that will redirect to the proper location on Init (Page_Init)

GoodEnough
+3  A: 

You can add the following elements into the Web.config. So it would only be set in one place:

<loginRedirectByRole>
  <roleRedirects>
      <add role="Administrator" url="~/Admin/Page.aspx" />
      <add role="User" url="~/User/Page.aspx" />
  </roleRedirects>
</loginRedirectByRole>

You would still have to do the redirect in code -see the full Article

cgreeno
A: 
HttpContext.Current.Response.RedirectLocation

"gets or sets the redirectlocation in the HTTP header 'location'"

this is originally set by the "ReturnUrl" in the querystring.

rizzle