【发布时间】:2011-06-08 16:46:10
【问题描述】:
我会看看我是否可以足够清楚地解释这一点。我有 2 个网络表单。一个是基本的表单身份验证登录页面,另一个表单显示来自多个服务器的任务。我正在创建一个存储用户 ID 的 cookie。这是我的 cookie 的代码:
FormsAuthenticationTicket tkt = new FormsAuthenticationTicket(1, txtUser.Text, DateTime.Now, DateTime.Now.AddMinutes(120), true, rdr.GetInt32(0).ToString(), FormsAuthentication.FormsCookiePath);
string hash = FormsAuthentication.Encrypt(tkt);
HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);
在我的另一个表单中,我有一个下拉框,它按服务器 IP 显示服务器表中的所有服务器。
public void Populate()
{
SqlConnection myConnection1 = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString);
myConnection1.Open();
SqlCommand cmd1 = new SqlCommand("SELECT ServerIP FROM Servers", myConnection1);
SqlDataReader dropReader;
dropReader = cmd1.ExecuteReader();
drpChoose.DataSource = dropReader;
drpChoose.DataTextField = "ServerIP";
drpChoose.DataValueField = "ServerIP";
drpChoose.DataBind();
}
我在页面加载中调用填充。我有另一个存储权限的表。它具有 UserID、ServerID 和 Permission(读取或执行)。假设 UserID 1 仅与 IP 为 192.168.0.10 的 ServerID 1 相关联。如何让这个服务器 IP 显示在下拉列表中?我很确定如果我将 cookie 传递到可以从中获取 UserID 的第二种形式,但我不知道从哪里开始。
如果我没有提供足够的信息,我深表歉意。如果需要,我会提供更多。
【问题讨论】: