Cookie无法在ASP.NET网站上运行 [英] Cookies are not working on ASP.NET site
问题描述
您好我正在通过操作Cookie从头开始创建登录模块。出于某种原因,只有当我使用Firefox(localhost)时才会推送cookie,当我尝试托管网站时,它从未推送过。我尝试将过期时间更改为几天,只是为了确保服务器的时间差不会导致它过期,但它仍然存在。
Response.Cookies [ UNup]。Value = UN_up;
Response.Cookies [ Role]。Value = Convert.ToString(role);
Response.Cookies [ UNup]。Expires = DateTime.Now.AddDays(< span class =code-digit> 3 );
Response.Cookies [ Role]。Expires = DateTime.Now.AddDays(< span class =code-digit> 3 );
UN_up = string .Empty;
role = 0 ;
Response.Redirect( http://betatesterpeak-001-site1.smarterasp.net/1.aspx 跨度>);
是否有其他版本的cookies我可以用于所有这些浏览器,或者我只是编码错了?
我使用的浏览器:
Chrome:31.0.1650.57 m
Firefox:25
Safari:5
IE:9
谢谢!
一般我写的Cookie喜欢如下所示
HttpCookie appCookie = new HttpCookie( varname);
appCookie.Value = value;
appCookie.Expires = DateTime.Now.AddDays( 1 );
appCookie.Path = / Application1;
Response.Cookies.Add(appCookie);
并且要取回
if (Request.Cookies [ userName]!= null )
Label1.Text = Request.Cookies [ userName]。 value
和它Genraaly工作
我认为你应该尝试应用程序路径而不是完整的Http网址因为根据我的知识,申请后cookie无法访问
尝试
Response.Redirect(Server.MapPath()+page。 aspx)
或只是
Response.Redirect(page.aspx)
我希望帮助
Hi I am making a log in module from scratch by manipulating cookies. For some reason the cookies are only pushed when I use Firefox (localhost) and when I tried hosting the site it never pushed. I tried changing the expiration to a couple of days, just to be sure that the server's time difference is not causing it to expire but it still does.
Response.Cookies["UNup"].Value = UN_up;
Response.Cookies["Role"].Value = Convert.ToString(role);
Response.Cookies["UNup"].Expires = DateTime.Now.AddDays(3);
Response.Cookies["Role"].Expires = DateTime.Now.AddDays(3);
UN_up = string.Empty;
role = 0;
Response.Redirect("http://betatesterpeak-001-site1.smarterasp.net/1.aspx");
Are there other versions of cookies that I can use for all these browsers or am I just coding this wrong?
The browsers I used:
Chrome: 31.0.1650.57 m
Firefox: 25
Safari: 5
IE: 9
Thanks!
Generally I do Write Cookie Like As Follows
HttpCookie appCookie = new HttpCookie("varname"); appCookie.Value = "value"; appCookie.Expires = DateTime.Now.AddDays(1); appCookie.Path = "/Application1"; Response.Cookies.Add(appCookie);
And To Retrieve
if(Request.Cookies["userName"] != null) Label1.Text =Request.Cookies["userName"].value
And It Genraaly Works
I Think You Should Try a Application Path Instead of full Http url because cookie can't be access after application as per my knowledge
try
Response.Redirect(Server.MapPath()+"page.aspx")
or just
Response.Redirect("page.aspx")
I hope That Help
这篇关于Cookie无法在ASP.NET网站上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!