tags:

views:

25

answers:

2

When someone logs on to my site. I want to direct them to their own home page. If the user has the id of 1. They would go to

http://www.test.com/Home.aspx?id=1

I already have the login and id setup. I am not sure how to incorporate it into the url.

+3  A: 
Response.Redirect("http://www.test.com/Home.aspx?id=" + id);
Tom Vervoort
+1  A: 

Are you using Forms Authentication?

If so, instead of using RedirectFromLoginPage (which will redirect to whatever page is in your web.config), just use FormsAuthentication.SetAuthCookie, and do your own redirection.

To do so, you need to make use of the URL QueryString.

E.g

// forms auth code here, user is logged in.
int id = 1;
string redirectUrlFormat = "http://www.test.com/Home.aspx{0}";
string queryStringidFormat = "?id={0}";
Response.Redirect(string.Format(redirectUrlFormat, string.Format(queryStringidFormat, id)));

You should handle all querystring parameters, URL, etc (ie the above code) in a global static model class.

That way you can just say:

Response.Redirect(SomeStaticClass.GetUserHomePageUrl(id));

In the receiving page (Home.aspx), use the following code to get the id of the user:

var userId = Request.QueryString["id"]; // again, this "magic string" should be in a static class.

Hope that helps.

RPM1984