Authentication/Automatic Redirect?

Discussion in 'ASP .Net' started by Donald Williamson, Nov 24, 2003.

  1. Hi

    Hope someone can help me with authentication and how the redirects work. I'
    ve already tried searching previous posts but didn't really find anything.

    for I have a page that checks to see if the user has logged in. If not, it
    redirects them to the login page for authentication. After authenticating, I
    want to redirect them back to the original page that sent them. I always get
    redirected back to the default page. I noticed that the '?RedirectURL'
    parameter is not being set so my question is how does this get set?

    Here's me web.config code"
    <authentication mode="Forms" >
    <forms
    name="fpSupport"
    path="/"
    loginUrl="Accounts/Login.aspx"
    protection="All"
    timeout="30">
    </forms>
    </authentication>


    Here's the code that redirects them to the login page if they are not
    authenticated:
    If Not Context.User.Identity.IsAuthenticated Then
    Response.Redirect("Accounts/Login.aspx")
    End If


    And here's the code on the login page after they have been authenticated:

    FormsAuthentication.SetAuthCookie(UserName.Text, chkPersist.Checked)
    FormsAuthentication.RedirectFromLoginPage(UserName.Text,
    chkPersist.Checked)

    Any assistance would greatly be appreciated!

    - Donald
    Donald Williamson, Nov 24, 2003
    #1
    1. Advertising

  2. "Donald Williamson" <> wrote in message
    news:%...
    > Hi
    >
    > Hope someone can help me with authentication and how the redirects work.

    I'
    > ve already tried searching previous posts but didn't really find anything.
    >
    > for I have a page that checks to see if the user has logged in. If not,

    it
    > redirects them to the login page for authentication. After authenticating,

    I
    > want to redirect them back to the original page that sent them. I always

    get
    > redirected back to the default page. I noticed that the '?RedirectURL'
    > parameter is not being set so my question is how does this get set?
    >
    > Here's me web.config code"
    > <authentication mode="Forms" >
    > <forms
    > name="fpSupport"
    > path="/"
    > loginUrl="Accounts/Login.aspx"
    > protection="All"
    > timeout="30">
    > </forms>
    > </authentication>



    If you're using Forms Authentication, your code should not be checking to
    see if the user is authenticated. Instead, set up the <authorization>
    section properly, and Forms Authentication will do it for you.
    --
    John Saunders
    John.Saunders at SurfControl.com
    John Saunders, Nov 24, 2003
    #2
    1. Advertising

  3. Thanks John,

    One more question about the <authorization>. I am setting up many multiple
    directories. I only want to give anonymous permission to a few select
    files. Most others will require that they be authenticated to view the files
    in most of the directories.



    Do I create a separate <authorization> config file for each directory that
    needs to be authenticated or what is the best way to do this? Thanks again
    for any help.



    - Donald


    >
    > If you're using Forms Authentication, your code should not be checking to
    > see if the user is authenticated. Instead, set up the <authorization>
    > section properly, and Forms Authentication will do it for you.
    > --
    > John Saunders
    > John.Saunders at SurfControl.com
    >
    >
    Donald Williamson, Nov 25, 2003
    #3
  4. "Donald Williamson" <> wrote in message
    news:...
    > Thanks John,
    >
    > One more question about the <authorization>. I am setting up many

    multiple
    > directories. I only want to give anonymous permission to a few select
    > files. Most others will require that they be authenticated to view the

    files
    > in most of the directories.
    >
    >
    >
    > Do I create a separate <authorization> config file for each directory that
    > needs to be authenticated or what is the best way to do this? Thanks again
    > for any help.


    You can put a separate web.config in each directory if you like. Mostly,
    people use <location> elements to specify the configuration of the
    subdirectories.
    --
    John Saunders
    John.Saunders at SurfControl.com
    John Saunders, Nov 25, 2003
    #4
  5. Thanks again John,

    Getting closer ... hopefully my last question :) I'm working on the
    location path. Here's what I have in my web.config:

    <location path="~/Modules/SupportViewRequests/viewrequest.aspx">
    <system.web>
    <authorization>
    <deny users="*" />
    </authorization>
    </system.web>
    </location>

    This is placed before the main <system.web> settings where, in part, I have
    the following:
    <authentication mode="Forms" >
    <forms
    name="fpSupport"
    path="/"
    loginUrl="Accounts/Login.aspx"
    protection="All"
    timeout="30">
    </forms>
    </authentication>

    I did remove the redirect in my main page. However, I'm never automatically
    getting redirected to the log-in page. What am I missing?

    - Donald

    >
    > You can put a separate web.config in each directory if you like. Mostly,
    > people use <location> elements to specify the configuration of the
    > subdirectories.
    > --
    > John Saunders
    > John.Saunders at SurfControl.com
    >
    >
    Donald Williamson, Nov 26, 2003
    #5
  6. Got it! FYI here's the correct code to lock the directory:

    <location path="Modules/SupportViewRequests">
    <system.web>
    <authorization>
    <deny users="?" />
    </authorization>
    </system.web>
    </location>

    - Donald

    "Donald Williamson" <> wrote in message
    news:...
    > Thanks again John,
    >
    > Getting closer ... hopefully my last question :) I'm working on the
    > location path. Here's what I have in my web.config:
    >
    > <location path="~/Modules/SupportViewRequests/viewrequest.aspx">
    > <system.web>
    > <authorization>
    > <deny users="*" />
    > </authorization>
    > </system.web>
    > </location>
    >
    > This is placed before the main <system.web> settings where, in part, I

    have
    > the following:
    > <authentication mode="Forms" >
    > <forms
    > name="fpSupport"
    > path="/"
    > loginUrl="Accounts/Login.aspx"
    > protection="All"
    > timeout="30">
    > </forms>
    > </authentication>
    >
    > I did remove the redirect in my main page. However, I'm never

    automatically
    > getting redirected to the log-in page. What am I missing?
    >
    > - Donald
    >
    Donald Williamson, Nov 26, 2003
    #6
  7. "Donald Williamson" <> wrote in message
    news:...
    > Thanks again John,
    >
    > Getting closer ... hopefully my last question :) I'm working on the
    > location path. Here's what I have in my web.config:
    >
    > <location path="~/Modules/SupportViewRequests/viewrequest.aspx">
    > <system.web>
    > <authorization>
    > <deny users="*" />
    > </authorization>
    > </system.web>
    > </location>
    >
    > This is placed before the main <system.web> settings where, in part, I

    have
    > the following:
    > <authentication mode="Forms" >
    > <forms
    > name="fpSupport"
    > path="/"
    > loginUrl="Accounts/Login.aspx"
    > protection="All"
    > timeout="30">
    > </forms>
    > </authentication>
    >
    > I did remove the redirect in my main page. However, I'm never

    automatically
    > getting redirected to the log-in page. What am I missing?


    Where's your main <authorization> element?
    --
    John Saunders
    John.Saunders at SurfControl.com
    John Saunders, Nov 26, 2003
    #7
    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. David Kleyman

    Authentication/Automatic redirection question

    David Kleyman, Dec 17, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    638
    David Kleyman
    Dec 17, 2003
  2. Guest
    Replies:
    1
    Views:
    746
    Guest
    Jun 29, 2004
  3. ABC
    Replies:
    3
    Views:
    6,720
  4. ABC
    Replies:
    3
    Views:
    4,282
    Juan T. Llibre
    Apr 6, 2006
  5. Sal
    Replies:
    1
    Views:
    370
Loading...

Share This Page