查询字符串问题 [英] Querystring problem

查看:49
本文介绍了查询字符串问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有主页..在这里我通过标签显示欢迎消息...

根据他们的登录信息打印不同的用户名.


我从不同页面单击userimage时遇到的问题.当它通过querystring重定向到首页时,在不同的id上打印相同的用户名. plz帮助槽示例


我的tbluser表包含:
id
用户名
userimage

i have home page .. where i show welcome message through label ...

that print different user name based on their login.


the problem i got when i click on userimage from differnt page.. it print same username.. on differnt id when it redirect to homepage by querystring. plz help trough example


my tbluser table contain:
id
username
userimage

推荐答案

假设您的主页为Home.aspx

并且,您还有另一个页面UserList.aspx,其中有用户的图像.

单击用户图像时,可以使用QueryString参数将其重定向到Home.aspx,如下所示:

Suppose your home page is Home.aspx

And, you have another page UserList.aspx where you have the images of the users.

When you click on the image of a user, you can redirect to the Home.aspx with a QueryString parameter as follows:

Response.Redirect("Home.aspx?UserId=" + userId");



Home.aspx.csPage_Load()方法中,您从查询字符串中读取UserId ,然后使用UserId 从数据库中检索用户并显示用户名.例如:



In the Page_Load() method of Home.aspx.cs you read the UserId from the Query String and then retrieve the user from the database using the UserId and show user name. For example:

int UserId= 0;
if(Request.Params["UserId"] != null)
{
    UserId = Convert.ToInt32(Request.Params["UserId"]);
}
if(UserId> 0)
{
    User user = GetUserFromDB(UserId)
    PopulateUI(user);
}


听起来像您单击用户图像时查找/传递用户名的逻辑缺陷.

不看代码就很难具体说明,但是看起来您访问用户ID的方式使它成为所有人的共同对象,就像使用应用程序对象来存储它一样!

如果要使用查询字符串根据ID选择用户名/用户图像,则需要确保每次尝试都检索它们.
Sounds like some flaw in your logic to find/pass the username when you click on the user-image.

It would be hard to be specific without seeing the code but looks like the way you are accessing the user id makes it common for all, like using an application object to store it!

If you are using querystring to pick the username/userimage based on ID, then you need to be sure that you are retriving them everytime you are trying to.


这篇关于查询字符串问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆