Quick ? on Forms Authentication

O

oakleyx

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,
 
K

Karl Seguin

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
 
S

Scott Mitchell [MVP]

oakleyx said:
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
(e-mail address removed)
http://www.4GuysFromRolla.com

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

Guest

Hi Guys,
So what does :-
Response.Redirect(FormsAuthentication.GetRedirectUrl(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!
 
O

oakleyx

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top