1

我有一个名为 profile.aspx 的页面,您可以通过一个菜单访问它,当您单击它时,您会进入您自己的个人资料(如果您已登录),但随后我创建了一个包含另一个个人资料图像的超链接。当您单击它时,我想在同一页面 profile.aspx 上显示此配置文件。但我不知道该怎么做,因为如果我链接到 profile.aspx,我肯定会访问我自己的个人资料。

我在其他页面中看到,当您单击个人资料时,网址将类似于 facebook.com/member1 以将所有个人资料彼此分开。这是一个可能的解决方案吗?

4

1 回答 1

1

当您使用唯一 ID 为您的个人资料页面获取数据时,您可以遵循以下可能的解决方案:

登录时,将您的唯一 ID 保存在会话变量中 -

Session["myID"]= "your id fetched from database";

当您单击另一个人的图像的超链接时,使用查询字符串概念将该用户的唯一 ID 附加到 url。

Response.Redirect("profile.aspx?ID="userID"); //the userID will be the user's uniqueID.

当您从菜单中单击配置文件页面时,附加会话值:

Response.Redirect("profile.aspx?ID=Session["myID"].toString());

然后在页面加载中profile.aspx你可以这样做:

private void Page_Load(object sender, System.EventArgs e)
{
    string receivedID = Request.QueryString["ID"].toString();
    if(receivedID == Session["myID"].toString())
    {
      //this is yourself, so fetch your data from DB
    }
    else
    {
      //fetch the data of the receivedID passed in querystring(URL)
    }
}
于 2013-01-04T09:40:10.673 回答