473,323 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

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,
Nov 18 '05 #1
5 1757
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
http://www.openmymind.net/
"oakleyx" <Da*********@gmail.com> wrote in message
news:db**************************@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,

Nov 18 '05 #2
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 - http://www.aisto.com/roeder/dotnet/ - 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():
http://tinyurl.com/66syy

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
Nov 18 '05 #3
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 - http://www.aisto.com/roeder/dotnet/ - 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():
http://tinyurl.com/66syy

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #4
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" <Pa*********@discussions.microsoft.com> wrote in message news:<B7**********************************@microso ft.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 - http://www.aisto.com/roeder/dotnet/ - 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():
http://tinyurl.com/66syy

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #5
Check out: http://blogs.msdn.com/bleroy/archive...03/207486.aspx

I think you'll find your answer..

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"oakleyx" <Da*********@gmail.com> wrote in message
news:db**************************@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" <Pa*********@discussions.microsoft.com> wrote in message

news:<B7**********************************@microso ft.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 - http://www.aisto.com/roeder/dotnet/ - 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(): http://tinyurl.com/66syy

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Billy Jacobs | last post by:
I have a website which has both secure and non-secure pages. I want to uses forms authentication. How do I accomplish this? Originally I had my web.config file in the root with Forms...
4
by: Greg Burns | last post by:
I have built a web app that uses forms authentication. There isn't a "remember me" feature (i.e. the authentication cookie is not permanent). When you close the browser, and open a new one, you...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
2
by: Eric | last post by:
I am trying to build an app where the stuff in the root directory is open to all, but anything under the Restricted directory requires you to login and I want to use Forms to do it. I'm having...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
7
by: Justin | last post by:
I am trying to password protect a subdirectory using forms authentication. I am using the "Location" tag to specify the directory to be protected. The login.aspx page is in the root directory of...
5
by: V. Jenks | last post by:
Using forms authentication, can I control which pages and/or directories a user would have access to or is that only available with Windows authentication? Thanks!
4
by: =?Utf-8?B?R3V1czEyMw==?= | last post by:
Hi, I created a web site on a remote server. To logon the user must enter a user id and password. The site is uses Forms Authentication. The web config file looks as follows: ...
4
by: Bjorn Sagbakken | last post by:
In a web-application with login creds (user, pwd), these are checked against a user table on a SQL server. On a positive validation I have saved the userID, name, custno and role-settings in a...
5
by: Rory Becker | last post by:
Having now created a Custom MembershipProvider that seems to work correctly with my Logon and ChangePassword controls, I am, as they say, a happy bunny. The next stange is to move on to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.