【发布时间】:2016-06-27 05:19:18
【问题描述】:
我不断收到调试错误“无法将类型 'string' 隐式转换为 'int'”。
我将出现该错误的文本加粗。
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie httpCookie = Request.Cookies["UserInfo"];
if (httpCookie == null)
{
txtDiv.Visible = true;
}
else
{
msgDiv.Visible = true;
string userName = httpCookie.Values["Name"].ToString();
WelcomeLabel.Text = "Welcome Back Mr. "+userName;
}
}
protected void SignupButton_Click(object sender, EventArgs e)
{
// Error in Below Line.
HttpCookie httpCookie = new HttpCookie["UserInfo"];
httpCookie.Values.Add("Name", NameTextBox.Text);
httpCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(httpCookie);
Response.Redirect("Thanks.aspx?name="+NameTextBox.Text);
// Server.Transfer("Thanks.aspx");
}
我也把它改成 new HttpCookie["UserInfo"].ToString();但是错误.......
【问题讨论】:
标签: c# asp.net httpcookie