【发布时间】:2014-04-20 07:01:22
【问题描述】:
我无法理解 Page.Request.QueryString 和 Page.Session 的工作原理。我如何将name 分配给这个string
protected override void Render(HtmlTextWriter output)
{
SqlConnection sqlConnection = new SqlConnection(connectionString);
SqlCommand sqlCommand = new SqlCommand();
StringBuilder stringBuilder1 = new StringBuilder();
StringBuilder stringBuilder2 = new StringBuilder();
sqlCommand.Connection = sqlConnection;
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = "proc_UserBids";
sqlCommand.CommandTimeout = 1000;
string str = this.Page.Request.QueryString["name"] == null ? this.Page.Session["name"].ToString() : ((object)this.Page.Request.QueryString["name"]).ToString();
if (!(str == ""))
{
//Do Something
}
}
我得到的错误是:
异常详细信息:System.NullReferenceException:对象引用未设置为对象的实例。
string str = this.Page.Request.QueryString["name"] == null ? this.Page.Session["name"].ToString() : ((object)this.Page.Request.QueryString["name"]).ToString();
【问题讨论】:
-
您既没有查询字符串也没有键为“name”的会话
标签: c# asp.net custom-server-controls htmltextwriter