本文介绍了Cookies参考在ashx文件中获取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了设置cookie并获取cookie


// set cookie
 HttpCookie cookie = new HttpCookie("uid");
                cookie.Value =user.ID;
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);



//get cookie in ashx file

HttpCookie cookie = context.Request.Cookies.Get("uid");
string id = cookie.Value;


在上面的代码中,我首先设置了cookie,但是当我尝试在ashx文件中获取cookie值时(请参见下面的代码),则cookie对象为null,而这可以在aspx文件中轻松运行,而在ashx文件中为null. ="h2_lin">解决方案


I have used set cookies and get cookies


// set cookie
 HttpCookie cookie = new HttpCookie("uid");
                cookie.Value =user.ID;
                cookie.Expires = DateTime.Now.AddDays(1);
                Response.Cookies.Add(cookie);



//get cookie in ashx file

HttpCookie cookie = context.Request.Cookies.Get("uid");
string id = cookie.Value;


In the above code first i have set cookies, but when i try to get cookies value in ashx file(see in the below code) then cookie object is null while this can run easily in aspx file but null in ashx file.

解决方案


这篇关于Cookies参考在ashx文件中获取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 06:10