最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how read cookie value using javascript created in Asp.net C# - Stack Overflow

programmeradmin1浏览0评论

I am using ASP MVC 2.0 , i want to set Cookie from my Controller and read it from java Script i there any way to do so i have used following code in controller

HttpCookie ActiveTabs = new HttpCookie("tabs");
ActiveTabs.Values["top_navi_link"] = "ViewConference";
Response.Cookies.Add(ActiveTabs);

how to read it from java script.

I am using ASP MVC 2.0 , i want to set Cookie from my Controller and read it from java Script i there any way to do so i have used following code in controller

HttpCookie ActiveTabs = new HttpCookie("tabs");
ActiveTabs.Values["top_navi_link"] = "ViewConference";
Response.Cookies.Add(ActiveTabs);

how to read it from java script.

Share Improve this question edited Feb 13, 2012 at 13:32 Gaurav Mishra asked Feb 13, 2012 at 13:24 Gaurav MishraGaurav Mishra 711 silver badge5 bronze badges 4
  • 1 Use Google. w3schools./js/js_cookies.asp – CBusBus Commented Feb 13, 2012 at 13:26
  • 3 @SOliver, w3schools? Seriously? There are also w3fools – Darin Dimitrov Commented Feb 13, 2012 at 13:30
  • 1 @DarinDimitrov: Yes seriously; they provide a adequate solution to the OP's problem. w3fools are claiming that there is a lot of questionable content on the site, not that every item on it is wrong. – CBusBus Commented Feb 13, 2012 at 13:45
  • I agree with SOliver here. Most of W3Schools is good info, but there are quite a few bad ones. And the bulk of the "bad ones" are very nitpicky. – Darthg8r Commented Feb 13, 2012 at 14:46
Add a ment  | 

2 Answers 2

Reset to default 4

Use this jquery jquery-cookies.js which make it easy:

var cookiedata = $.cookie('top_navi_link');
<script type="text/javascript">
    alert(document.cookie);
</script>

There are also some jquery plugins such as jquery.cookie which might simplify this task.

发布评论

评论列表(0)

  1. 暂无评论