2010-09-08 33 views
2

当有人登录到我的网站时。我想引导他们到他们自己的主页。如果用户的ID为1.他们会去根据用户数据重定向到url

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

我已经有登录名和ID设置。我不知道如何将它合并到网址中。

回答

1

您使用的是Forms Authentication吗?

如果是这样,而不是使用RedirectFromLoginPage(它将重定向到web.config中的任何页面),只需使用FormsAuthentication.SetAuthCookie,并执行自己的重定向。

为此,您需要使用网址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))); 

你应该处理所有的查询字符串参数,URL等(即上面的代码)在全球静态模型类。

这样,你可以只说:

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

在接收页面(Home.aspx),使用下面的代码来获取用户的ID:

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

希望帮助。

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