Page 1 of 1

Setting a landing page on logging in.

Posted: Wed Jan 12, 2011 11:41 am
by deverill
Summary: We have a store that we need to send a person to a certain page when logged in, based on their info.

Our store sells tickets for tours in many different cities. We have set up our ticket sellers as users in the store and have used ac_UserSettings to store information about them. One bit of info is the page they should default to when logging in. A ticket seller in Key West should start on the Key West page when logging in, not Boston or the main page.

I'm hoping for some idea of the best way to redirect a person to a page named in UserSettings when they successfully log in.

Thanks!

Re: Setting a landing page on logging in.

Posted: Thu Jan 13, 2011 5:24 am
by mazhar
Well if you want every user to go to same page then you can do it via web.config file.
viewtopic.php?f=42&t=13057

In case every user has his own page upon login then you can do the following. First create one more root level page for example let's call it RedirectManger.aspx. Then alter the web.config in a way mentioned in above thread and make it redirect user to RedirectManger.aspx upon login. Now in RedirectManger.aspx you need to do some custom code to handle user specific redirect for example

Code: Select all

string userPage = Token.Instance.User.Settings.GetValueByKey("UserPageName");
Response.Redirect("~/"+userPage);

Re: Setting a landing page on logging in.

Posted: Thu Jan 13, 2011 7:08 am
by deverill
Great, thank you Mazhar.

I knew it wouldn't be too hard - I am really enjoying working with AC7 after AC5 for all those years. It's an excellently done product.

Regards,
Jim

Re: Setting a landing page on logging in.

Posted: Thu Jan 13, 2011 11:02 am
by deverill
Mazhar,
As I went over your method I realized the Global.ascx is already doing some custom stuff in our store and I wanted to avoid adding a new page if possible so here's my complete solution based on your help, in case it can help anyone else. In (a custom copy of) LoginDialog.ascx.cs in LoginButton_Click I changed the code right after the check for expired passwords to this:

Code: Select all

// Begin Mod LandingPageMod
//	Purpose: Send the successfully logged-in user to the landing page set in their UserSettings field named LandingPage.
//	If the UserSettings field does not exist or is blank then do the default action.
//    Note: There is no error checking on the contents of the LandingPage field.  If it is incorrect the visitor will
//             get the wrong page if it is able to parse a store page or a Resource Not Found error otherwise.
//             Use with caution.
							
User user = UserDataSource.LoadForUserName(UserName.Text);               //Get username they are logging in as.
string userPage = user.Settings.GetValueByKey("LandingPage");            //Load that user's UserSettings/LandingPage field.

if (String.IsNullOrEmpty(userPage)) {                                    // go to the default page or calling page.
        FormsAuthentication.RedirectFromLoginPage(UserName.Text, false);
} else {                                                                 // Go to the specified landing page.								
        FormsAuthentication.SetAuthCookie(UserName.Text, false);
        Response.Redirect("~/" + userPage );																
}
// End Mod LandingPageMod
Hope it helps someone else and thanks for your help!
Jim