Quick ? on Forms Authentication

Ask a Question related to ASP.NET Security, Design and Development.

  1. #1

    Default Quick ? on Forms Authentication

    Hi,

    I'm using asp.net form authentication. The problem i'm having is when
    my cookie expires it redirects me to the login page, so I log in again
    and it brings me to the page that I was on last before the cookie
    expired.

    Is there something I can do so that after I login it always redirect
    to the Default.aspx page?

    Thanks,
    oakleyx Guest

  2. Similar Questions and Discussions

    1. Accessing htm files without authentication (forms authentication)
      I have application with forms authentication. All works fine. When user opens .aspx file gets login form, login and then get the .aspx page. But...
    2. ASP.Net Forms authentication with basic authentication popup
      Relatively new to ASP.Net but have a strange problem. My site uses forms authentication for a large administration section however after the user...
    3. Forms authentication then redirection to a secure web with NT authentication?
      Hi, I want to allow access to particular secured intranet web sites. These intranet are stored in sharepoint (2003 version) Actually I've...
    4. Authentication ticket, cookieless, forms authentication?
      Hi. I want to use Forms Authentication, cookieless. The issue is setting the Authentication Ticket without using cookies (!) That is, the...
    5. Forms authentication with Windows authentication
      Hi, I have an ASP.NET web site that uses IIS Basic Authentication and accesses an OLAP Server at various stages. The OLAP Server authentication...
  3. #2

    Default Re: Quick ? on Forms Authentication

    Instead of using RedirectFromLoginPage (which does what you describe), you
    can use


    ForumsAutnetication.SetAuthCookie() (same parameters as
    RedirectFromLoginPage()) and then redirect yourself via
    Response.Redirect(...)

    Karl

    --
    MY ASP.Net tutorials
    [url]http://www.openmymind.net/[/url]


    "oakleyx" <Daniel.Peck@gmail.com> wrote in message
    news:db7b62fd.0410270706.24dd5a48@posting.google.c om...
    > Hi,
    >
    > I'm using asp.net form authentication. The problem i'm having is when
    > my cookie expires it redirects me to the login page, so I log in again
    > and it brings me to the page that I was on last before the cookie
    > expired.
    >
    > Is there something I can do so that after I login it always redirect
    > to the Default.aspx page?
    >
    > Thanks,

    Karl Seguin Guest

  4. #3

    Default Re: Quick ? on Forms Authentication

    oakleyx wrote:
    > I'm using asp.net form authentication. The problem i'm having is when
    > my cookie expires it redirects me to the login page, so I log in again
    > and it brings me to the page that I was on last before the cookie
    > expired.
    >
    > Is there something I can do so that after I login it always redirect
    > to the Default.aspx page?
    Daniel, the reason it's redirecting you to the page you were on is
    because you are calling FormsAuthentication.RedirectFromLoginPage() to
    log the user on from your Logon.aspx page, no? This, as its name
    implies, redirects the user back to the page they came from.

    Using Reflector - [url]http://www.aisto.com/roeder/dotnet/[/url] - you can see that
    this method simply calls FormsAuthentication.SetAuthCookie(), and then
    manually does a Response.Redirect(). So, if you want to send users to
    Default.aspx from your Logon page, when they login, instead of using
    RedirectFromLongPage(), use SetAuthCookie() and then
    Response.Redirect("Default.aspx")

    Here's a link to the technical docs for FormsAuthentication.SetAuthCookie():
    [url]http://tinyurl.com/66syy[/url]

    Happy Programming!

    --

    Scott Mitchell
    [email]mitchell@4guysfromrolla.com[/email]
    [url]http://www.4GuysFromRolla.com[/url]

    * When you think ASP.NET, think 4GuysFromRolla.com!
    Scott Mitchell [MVP] Guest

  5. #4

    Default Re: Quick ? on Forms Authentication

    Hi Guys,
    So what does :-
    Response.Redirect(FormsAuthentication.GetRedirectU rl(txtUsername.Text, false))
    do.
    When i use it it redirects me to default.aspx(Which i guess it returns the
    default/webform1.aspx which is set as start page).
    I have my timeout in web.config set to 2.
    Why doesn't my page i logged into expire after 2 minutes!
    And again after login in i have a button for SignOut( below)
    But after clicking that i can still see a page thats under that directory
    when its suppose to redirect me to a login page!
    Sub SignOut(objSender As Object, objArgs As EventArgs)
    'delete the users auth cookie and sign out
    System.Web.Security.FormsAuthentication.SignOut()
    Session.Abandon()
    'redirect the user to their referring page
    Response.Redirect("default.aspx")
    Any kind of advice needed!



    "Scott Mitchell [MVP]" wrote:
    > oakleyx wrote:
    > > I'm using asp.net form authentication. The problem i'm having is when
    > > my cookie expires it redirects me to the login page, so I log in again
    > > and it brings me to the page that I was on last before the cookie
    > > expired.
    > >
    > > Is there something I can do so that after I login it always redirect
    > > to the Default.aspx page?
    >
    > Daniel, the reason it's redirecting you to the page you were on is
    > because you are calling FormsAuthentication.RedirectFromLoginPage() to
    > log the user on from your Logon.aspx page, no? This, as its name
    > implies, redirects the user back to the page they came from.
    >
    > Using Reflector - [url]http://www.aisto.com/roeder/dotnet/[/url] - you can see that
    > this method simply calls FormsAuthentication.SetAuthCookie(), and then
    > manually does a Response.Redirect(). So, if you want to send users to
    > Default.aspx from your Logon page, when they login, instead of using
    > RedirectFromLongPage(), use SetAuthCookie() and then
    > Response.Redirect("Default.aspx")
    >
    > Here's a link to the technical docs for FormsAuthentication.SetAuthCookie():
    > [url]http://tinyurl.com/66syy[/url]
    >
    > Happy Programming!
    >
    > --
    >
    > Scott Mitchell
    > [email]mitchell@4guysfromrolla.com[/email]
    > [url]http://www.4GuysFromRolla.com[/url]
    >
    > * When you think ASP.NET, think 4GuysFromRolla.com!
    >
    Patrick.O.Ige Guest

  6. #5

    Default Re: Quick ? on Forms Authentication

    Hi Guys,

    Thanks for the tip.

    Everything works great, but I'm having a small problem. Just before I
    redirect to my Default.aspx page I set a session. When I try and call
    it later its null.

    Here is the code

    Session("whatever") = "hello"

    FormsAuthentication.SetAuthCookie(userName.Text, False,
    FormsAuthentication.FormsCookiePath)

    Response.Redirect("Default.aspx")

    But when I take the code out and put:

    Session("whatever") = "hello"
    FormsAuthentication.RedirectFromLoginPage(myReader ("userid"), False)

    The sessions works. Can any one explain why this is happening.

    Thanks,



    "Patrick.O.Ige" <PatrickOIge@discussions.microsoft.com> wrote in message news:<B710E73D-FB8C-4C32-A9EB-3387EFE21170@microsoft.com>...
    > Hi Guys,
    > So what does :-
    > Response.Redirect(FormsAuthentication.GetRedirectU rl(txtUsername.Text, false))
    > do.
    > When i use it it redirects me to default.aspx(Which i guess it returns the
    > default/webform1.aspx which is set as start page).
    > I have my timeout in web.config set to 2.
    > Why doesn't my page i logged into expire after 2 minutes!
    > And again after login in i have a button for SignOut( below)
    > But after clicking that i can still see a page thats under that directory
    > when its suppose to redirect me to a login page!
    > Sub SignOut(objSender As Object, objArgs As EventArgs)
    > 'delete the users auth cookie and sign out
    > System.Web.Security.FormsAuthentication.SignOut()
    > Session.Abandon()
    > 'redirect the user to their referring page
    > Response.Redirect("default.aspx")
    > Any kind of advice needed!
    >
    >
    >
    > "Scott Mitchell [MVP]" wrote:
    >
    > > oakleyx wrote:
    > > > I'm using asp.net form authentication. The problem i'm having is when
    > > > my cookie expires it redirects me to the login page, so I log in again
    > > > and it brings me to the page that I was on last before the cookie
    > > > expired.
    > > >
    > > > Is there something I can do so that after I login it always redirect
    > > > to the Default.aspx page?
    > >
    > > Daniel, the reason it's redirecting you to the page you were on is
    > > because you are calling FormsAuthentication.RedirectFromLoginPage() to
    > > log the user on from your Logon.aspx page, no? This, as its name
    > > implies, redirects the user back to the page they came from.
    > >
    > > Using Reflector - [url]http://www.aisto.com/roeder/dotnet/[/url] - you can see that
    > > this method simply calls FormsAuthentication.SetAuthCookie(), and then
    > > manually does a Response.Redirect(). So, if you want to send users to
    > > Default.aspx from your Logon page, when they login, instead of using
    > > RedirectFromLongPage(), use SetAuthCookie() and then
    > > Response.Redirect("Default.aspx")
    > >
    > > Here's a link to the technical docs for FormsAuthentication.SetAuthCookie():
    > > [url]http://tinyurl.com/66syy[/url]
    > >
    > > Happy Programming!
    > >
    > > --
    > >
    > > Scott Mitchell
    > > [email]mitchell@4guysfromrolla.com[/email]
    > > [url]http://www.4GuysFromRolla.com[/url]
    > >
    > > * When you think ASP.NET, think 4GuysFromRolla.com!
    > >
    oakleyx Guest

  7. #6

    Default Re: Quick ? on Forms Authentication

    Check out: [url]http://blogs.msdn.com/bleroy/archive/2004/08/03/207486.aspx[/url]

    I think you'll find your answer..

    Karl

    --
    MY ASP.Net tutorials
    [url]http://www.openmymind.net/[/url]


    "oakleyx" <Daniel.Peck@gmail.com> wrote in message
    news:db7b62fd.0410291246.567c3b3b@posting.google.c om...
    > Hi Guys,
    >
    > Thanks for the tip.
    >
    > Everything works great, but I'm having a small problem. Just before I
    > redirect to my Default.aspx page I set a session. When I try and call
    > it later its null.
    >
    > Here is the code
    >
    > Session("whatever") = "hello"
    >
    > FormsAuthentication.SetAuthCookie(userName.Text, False,
    > FormsAuthentication.FormsCookiePath)
    >
    > Response.Redirect("Default.aspx")
    >
    > But when I take the code out and put:
    >
    > Session("whatever") = "hello"
    > FormsAuthentication.RedirectFromLoginPage(myReader ("userid"), False)
    >
    > The sessions works. Can any one explain why this is happening.
    >
    > Thanks,
    >
    >
    >
    > "Patrick.O.Ige" <PatrickOIge@discussions.microsoft.com> wrote in message
    news:<B710E73D-FB8C-4C32-A9EB-3387EFE21170@microsoft.com>...
    > > Hi Guys,
    > > So what does :-
    > > Response.Redirect(FormsAuthentication.GetRedirectU rl(txtUsername.Text,
    false))
    > > do.
    > > When i use it it redirects me to default.aspx(Which i guess it returns
    the
    > > default/webform1.aspx which is set as start page).
    > > I have my timeout in web.config set to 2.
    > > Why doesn't my page i logged into expire after 2 minutes!
    > > And again after login in i have a button for SignOut( below)
    > > But after clicking that i can still see a page thats under that
    directory
    > > when its suppose to redirect me to a login page!
    > > Sub SignOut(objSender As Object, objArgs As EventArgs)
    > > 'delete the users auth cookie and sign out
    > > System.Web.Security.FormsAuthentication.SignOut()
    > > Session.Abandon()
    > > 'redirect the user to their referring page
    > > Response.Redirect("default.aspx")
    > > Any kind of advice needed!
    > >
    > >
    > >
    > > "Scott Mitchell [MVP]" wrote:
    > >
    > > > oakleyx wrote:
    > > > > I'm using asp.net form authentication. The problem i'm having is
    when
    > > > > my cookie expires it redirects me to the login page, so I log in
    again
    > > > > and it brings me to the page that I was on last before the cookie
    > > > > expired.
    > > > >
    > > > > Is there something I can do so that after I login it always redirect
    > > > > to the Default.aspx page?
    > > >
    > > > Daniel, the reason it's redirecting you to the page you were on is
    > > > because you are calling FormsAuthentication.RedirectFromLoginPage() to
    > > > log the user on from your Logon.aspx page, no? This, as its name
    > > > implies, redirects the user back to the page they came from.
    > > >
    > > > Using Reflector - [url]http://www.aisto.com/roeder/dotnet/[/url] - you can see
    that
    > > > this method simply calls FormsAuthentication.SetAuthCookie(), and then
    > > > manually does a Response.Redirect(). So, if you want to send users to
    > > > Default.aspx from your Logon page, when they login, instead of using
    > > > RedirectFromLongPage(), use SetAuthCookie() and then
    > > > Response.Redirect("Default.aspx")
    > > >
    > > > Here's a link to the technical docs for
    FormsAuthentication.SetAuthCookie():
    > > > [url]http://tinyurl.com/66syy[/url]
    > > >
    > > > Happy Programming!
    > > >
    > > > --
    > > >
    > > > Scott Mitchell
    > > > [email]mitchell@4guysfromrolla.com[/email]
    > > > [url]http://www.4GuysFromRolla.com[/url]
    > > >
    > > > * When you think ASP.NET, think 4GuysFromRolla.com!
    > > >

    Karl Seguin Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139