FormsAuthentication.RedirectFromLoginPage question

Discussion in 'ASP .Net' started by Alex Nitulescu, Feb 12, 2005.

  1. Hi. I have two questions, please:

    a) If I go DIRECTLY to Login, there's no Request.Params("ReturnURL"), and
    therefore RedirectFromLogin won't work, because it will try to go to a page
    named "Default", which in my case does not exist. Short of creating a
    "mandatory" Default page, what can I do ? RedirectFromLogin not only
    redirects me to whereever I came from, but it also creates a ticket - so how
    can I still use it if the redirection part is not convenient in my case
    (there's no Default.aspx page) ?
    Should I check whether Request.Params("ReturnURL") is null, and in this case
    set it somehow to the page I want the user to go after login ?
    Request.Params("ReturnURL") is read-only !

    b) If a user has several roles, how can I list them all ? Now I have some
    ugly code like:

    If User.IsInRole("Admin") Then
    strRole &= "<li>Administrator"
    End If
    If User.IsInRole("Sales") Then
    strRole &= "<li>Sales"
    End If
    If User.IsInRole("Support") Then
    strRole &= "<li>Support"
    End If
    If User.IsInRole("Guest") Then
    strRole &= "<li>Guest"
    End If
    lblRole.Text = User.Identity.Name & ", your application role is: <h2>" &
    strRole & "</h2> !"

    I'm asking this because of course there are ways to go around this, but I
    wanted to encapsulate this "role" thing in global.asax in
    Application_AuthenticateRequest. I could read again somewhere in my
    application my "roles" XMLFile (or dbTable) and list all the roles for user
    X, maybe even without checking for "IsInRole", but I'm looking for an
    elegant, OO solution to this problem. Should I write a function which reads
    all the roles for user X in an array and put this function in a module and
    call it as well from Application_AuthenticateRequest as from wherever else I
    need to list the roles for a specific user ?

    Thank you for bearing with me.
    Alex.
    Alex Nitulescu, Feb 12, 2005
    #1
    1. Advertising

  2. Alex Nitulescu

    Scott Allen Guest

    Hi Alex:

    For question 'a' - I'm not aware of a way to override the default.aspx
    URL of RedirectFromLogin. Someone else might have an idea.

    For question 'b' there is no quick and easy method to call,
    unforunately, but you can use the DirectorySearcher class from
    System.DirectoryServices to look up the user groups. For a sample, see
    the code in the following article:
    http://msdn.microsoft.com/library/d...ve_directory_authentication_from_asp__net.asp

    --
    Scott
    http://www.OdeToCode.com/blogs/scott/

    On Sat, 12 Feb 2005 02:13:43 -0500, "Alex Nitulescu"
    <> wrote:

    >Hi. I have two questions, please:
    >
    >a) If I go DIRECTLY to Login, there's no Request.Params("ReturnURL"), and
    >therefore RedirectFromLogin won't work, because it will try to go to a page
    >named "Default", which in my case does not exist. Short of creating a
    >"mandatory" Default page, what can I do ? RedirectFromLogin not only
    >redirects me to whereever I came from, but it also creates a ticket - so how
    >can I still use it if the redirection part is not convenient in my case
    >(there's no Default.aspx page) ?
    >Should I check whether Request.Params("ReturnURL") is null, and in this case
    >set it somehow to the page I want the user to go after login ?
    >Request.Params("ReturnURL") is read-only !
    >
    >b) If a user has several roles, how can I list them all ? Now I have some
    >ugly code like:
    >
    >If User.IsInRole("Admin") Then
    > strRole &= "<li>Administrator"
    >End If
    >If User.IsInRole("Sales") Then
    > strRole &= "<li>Sales"
    >End If
    >If User.IsInRole("Support") Then
    > strRole &= "<li>Support"
    >End If
    >If User.IsInRole("Guest") Then
    > strRole &= "<li>Guest"
    >End If
    >lblRole.Text = User.Identity.Name & ", your application role is: <h2>" &
    >strRole & "</h2> !"
    >
    >I'm asking this because of course there are ways to go around this, but I
    >wanted to encapsulate this "role" thing in global.asax in
    >Application_AuthenticateRequest. I could read again somewhere in my
    >application my "roles" XMLFile (or dbTable) and list all the roles for user
    >X, maybe even without checking for "IsInRole", but I'm looking for an
    >elegant, OO solution to this problem. Should I write a function which reads
    >all the roles for user X in an array and put this function in a module and
    >call it as well from Application_AuthenticateRequest as from wherever else I
    >need to list the roles for a specific user ?
    >
    >Thank you for bearing with me.
    >Alex.
    >
    Scott Allen, Feb 12, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaeHo Yoo
    Replies:
    1
    Views:
    504
    Teemu Keiski
    Jul 9, 2003
  2. Lauchlan M
    Replies:
    2
    Views:
    474
    John Saunders
    Aug 17, 2003
  3. Eric Broers
    Replies:
    1
    Views:
    793
    Steve C. Orr [MVP, MCSD]
    Nov 27, 2003
  4. Jacob Crossley
    Replies:
    0
    Views:
    386
    Jacob Crossley
    Apr 2, 2004
  5. Jacob Crossley
    Replies:
    0
    Views:
    329
    Jacob Crossley
    Apr 6, 2004
Loading...

Share This Page