ASP。 net c#Cookies [英] ASP . net c# Cookies
本文介绍了ASP。 net c#Cookies的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在ASP中实现cookie。 net c#program。它在本地机器上完美运行但是当我在线托管应用程序时它不起作用。
以下是创建cookie的代码
i am trying to implement cookies in ASP . net c# program. it works perfectly on the local machine but when i host the app online it does not work.
below is the code for creating the cookie
Response.Cookies["logvariables"]["username"] = dr["fullname"].ToString();
Response.Cookies["logvariables"]["userno"] = dr["userno"].ToString();
Response.Cookies["logvariables"]["usertype"] = dr["usertype"].ToString();
Response.Cookies["logvariables"]["LoginTime"] = System.DateTime.Now.ToLocalTime().ToString();
Response.Cookies["logvariables"]["trail_session_no"] = session_no;
这是我如何读取cookie
this how i read the cookie
string username = Request.Cookies["logvariables"]["username"] as string;
string LoginTime = Request.Cookies["logvariables"]["LoginTime"] as string;
有人可以帮忙!!!!
can someone please help!!!!
推荐答案
请使用下面的代码
/ /在这里使用参数声明一个HttpCookies
HttpCookie Cookies =新的HttpCookie(名称);
//清除Cookies
Response.Cookies.Clear();
//在其中设置一个值。
//这里Cookies对象就像一个类型,在'[]里面是一个Cookie的变量
Cookies [ID] = txtID.Text;
Cookies [MyName ] = txtName.Text;
Cookies [Contact_No] = txtContactNo.Text;
Cookies [EmailID] = txtEmailID.Text;
//将其添加到当前的网络回复中。
Response.Cookies.Add(Cookies);
//为饼干设置排序日期
HttpCookie Cookies1 =新的HttpCookie(过期);
Cookies1.Expires = DateTime.Now.AddDays(-1);
//重定向到另一页
Response.Redirect(Accepting_Cookies_Details.aspx);
< br $> b $ b
please use below code
// declaring a HttpCookies here with a Parameter
HttpCookie Cookies = new HttpCookie("Name");
//Clearing the Cookies
Response.Cookies.Clear();
// Set a value in it.
// here the Cookies object act like a type and inside the'[" "]' is a Cookie's variable
Cookies["ID"] = txtID.Text;
Cookies["MyName"] = txtName.Text;
Cookies["Contact_No"] = txtContactNo.Text;
Cookies["EmailID"] = txtEmailID.Text;
// Add it to the current web response.
Response.Cookies.Add(Cookies);
//Setting the Exparation Date For he Cookies
HttpCookie Cookies1 = new HttpCookie("Expiration");
Cookies1.Expires = DateTime.Now.AddDays(-1);
//Redirecting to another page
Response.Redirect("Accepting_Cookies_Details.aspx");
//Go the the target page where you want to retrieve your Cookies' values
protected void Page_Load(object sender, EventArgs e)
{
HttpCookie Cookie = Request.Cookies["Name"];
string ID1 = Cookie["ID"];
string MyName1 = Cookie["MyName"];
string Contact_No1 = Cookie["Contact_No"];
string EmailID1 = Cookie["EmailID"];
Literal1.Text = ID1;
Literal2.Text = MyName1;
Literal3.Text = Contact_No1;
Literal4.Text = EmailID1;
}
我希望这个链接可以帮助你 http://msdn.microsoft.com/en-us/library/ms178194.ASPX [ ^ ] [ ASP.NET中的Cookie [ ^ ]
I hope this link will be help you http://msdn.microsoft.com/en-us/library/ms178194.ASPX[^][Cookies in ASP.NET[^]
这篇关于ASP。 net c#Cookies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文