如何在C#中设置cookie值? [英] How to set cookie value in C#?

查看:402
本文介绍了如何在C#中设置cookie值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我在cookie中设置了值但是当我从另一个视图控制器访问viewbag中的值时,我找不到该值。

我非常感谢你的帮助



谢谢



我尝试了什么:



我试图在c#

Hi guys

I have set the value in the cookie but when I access that value in the viewbag from another view controller I can't find that value.
I would really appreciate you help

thanks

What I have tried:

I have tried to set cookie value in c#

推荐答案

以下是我在MVC中管理cookie的方法

Here's how I have been managing the cookies in MVC
[HttpGet]
public ActionResult Details()
{
  HttpCookie cookie = new HttpCookie("MySiteCookie", "For the love of Pete, do not put unencrypted info in cookies!");
  Response.SetCookie(cookie);
  return View();
}

[HttpPost]
public ActionResult Details(int i)
{
  HttpCookie cookie = Request.Cookies["MySiteCookie"];
  // do something with the cookie
  return View(new Model.SomeData(i));
}


Cookie是在未连接Web服务器和浏览器期间存储有关网站访问者数据的几种方法之一。 />


查看有关C中设置cookie值的有用资源#



C#.NET:在.NET中获取和设置Cookie值 [ ^ ]



ASP.Net C中的Cookie# [ ^ ]



ASP.Net C#中的Cookie# [ ^ ]
Cookies are one of several ways to store data about web site visitors during the time when web server and browser are not connected.

check this useful resources about set cookie value in C#

C# .NET: Get and Set Cookie Values in .NET[^]

Cookies in ASP.Net C#[^]

Cookies in ASP.Net C#[^]


这篇关于如何在C#中设置cookie值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆