Hi All,

I now creating the login page. So I have using the

ForumsAuthentication.RedirectFromLoginPage(UserName.Text,False)

So by default it will redirect to the default.aspx
So this part is ok. Can I redirect to the another file name?

Another problem is, I will do the checking wheter the user is login. If user are not log in it will redirect to login.aspx I wrote code like:

If Session("Logged_IN").Equals("No") Then
                Response.Redirect("login.aspx")
End If

But after I do the login and success, it will pop to the default.aspx. Can I redirect to the webpage where i original requested. I search from the web that ForumsAuthentication.RedirectFromLoginPage can redirect to caller webpage, but how? I feel blur!

Thanks
Best Regards
John Ang

Recommended Answers

All 4 Replies

Question 1: Can I redirect to the another file name?

Yes, by changing the default page settings in/under IIS

Question 2: But after I do the login and success, it will pop to the default.aspx. Can I redirect to the webpage where i original requested.

I am not sure what you are asking here? What page you originally requested?

Do you mean one that was entered into the address bar, but forced you to the Login page?? Yup, sure can once you have logged in the session is started, keep the browser open and on the default.aspx page and enter or select the address in the browser address bar that you were trying to get to...and voila!

Hope this helps?

Hi All,

I now creating the login page. So I have using the

ForumsAuthentication.RedirectFromLoginPage(UserName.Text,False)

So by default it will redirect to the default.aspx
So this part is ok. Can I redirect to the another file name?

Another problem is, I will do the checking wheter the user is login. If user are not log in it will redirect to login.aspx I wrote code like:

If Session("Logged_IN").Equals("No") Then
                Response.Redirect("login.aspx")
End If

But after I do the login and success, it will pop to the default.aspx. Can I redirect to the webpage where i original requested. I search from the web that ForumsAuthentication.RedirectFromLoginPage can redirect to caller webpage, but how? I feel blur!

Thanks
Best Regards
John Ang

For a little more flexibility you can use the FormsAuthentication class to create the ticket and then manually redirect.


You can use your Web.config file to set specific users or check against a database. Then use the following to set up your ticket and redirect:

FormsAuthentication.SetAuthCookie(Uname.Text, False)

Response.Redirect("yourpage.aspx")

Thanks,

Dustin

Hi,

You can use Server.Transfer instead of Response.Redirect to save a server round trip each time.

Loren Soth

Hi,

The code for the Button_Click() of Login page.

Sub Button_Click(By Val As Object, By Val As EventArgs)
If IsValid Then
If FormsAuthentication.Authenticate(txtUsername.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtUsername.Tex,False)
Else
lblMessage.Text="Bad Username/Password")
End If
End If

End Sub

The above code will first check the username and password passed by the user. If they are valid, it will return true and then go to the next statement. Next, it creates an authentication cookie, attaches it to the outgoing response and redirects user to original requested page. The second parameter specifies whether the aurhentication should be a session cookie (false) or a persistent cookie(true).

the code for Default page

Sun Signout(ByVal objSender As Object,ByVal objArgs EventArgs)
FormsAuthentication.SignOut()
Response.Redirect(Request.UrlReferrer.ToString())

The code for Page_Load method

If user.Identity.IsAuthenticated Then
lblMessage.Text="Sucessful"
Else
lblMessage.Text="Sorry"
End if
End Sub


Regards
bhar
Knowledge is power
http://www.vkinfotek.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.