简体   繁体   English

如何使用Asp.net C#中创建的JavaScript读取Cookie值

[英]how read cookie value using javascript created in Asp.net C#

I am using ASP.net 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 我正在使用ASP.net MVC 2.0,我想从我的控制器中设置Cookie并从Java脚本中读取它,我有任何方法可以这样做,因此我在控制器中使用了以下代码

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

how to read it from java script. 如何从Java脚本读取它。

<script type="text/javascript">
    alert(document.cookie);
</script>

There are also some jquery plugins such as jquery.cookie which might simplify this task. 还有一些jquery插件(例如jquery.cookie)可以简化此任务。

使用此jquery jquery-cookies.js使其变得容易:

var cookiedata = $.cookie('top_navi_link');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CORS:通过两种网站和客户端/服务器语言(javascript 和 ASP.NET C#)写入和读取 cookie - CORS: write and read a cookie through two website and client/server languages (javascript and ASP.NET C#) 使用ASP.NET时在JavaScript中创建的Cookie无法更新 - Cookie created in JavaScript not updating when using ASP.NET 在 javascript 中读取 cookie,由 asp.net c#code 制作 - read cookie in javascript , made by asp.net c#code 如何在asp.net mvc中使用razor viewmodel将c#guid值赋给javascript变量? - How to assign c# guid value to javascript variable using razor viewmodel in asp.net mvc? 如何在ASP.NET C#中使用javascript从ajax组合框中获取选定的值 - how to get selected value from ajax combobox using javascript in asp.net c# ASP.NET-如何使用C#显示JavaScript警报? - ASP.NET - How to display javascript alert using C#? 如何使用 javascript 调用 ASP.NET c# 方法 - how to call an ASP.NET c# method using javascript 如何使用C#在ASP.NET中的JavaScript函数中执行 - How to execute in JavaScript function in ASP.NET using C# C#(ASP.NET Razor)看不到的Javascript创建的Cookie - Cookies created by Javascript not seen by C# (ASP.NET Razor) 有什么方法可以读取由ASP.NET Core控制器中的JavaScript代码创建的cookie? - Is there any way to read a cookie created by JavaScript code in the Controller of ASP.NET Core?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM