c#方式操作cookie -尊龙游戏旗舰厅官网
尊龙游戏旗舰厅官网
收集整理的这篇文章主要介绍了
c#方式操作cookie
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1、设置cookie
public static void setcookie(string tokenvalue){httpcookie tokencookie = new httpcookie("localtoken");tokencookie.value = tokenvalue;//tokencookie.values.set("userid", user.key);var domain = webconfighelper.getwebconfigvalue("cookiesdomain");if (!string.isnullorwhitespace(domain)){tokencookie.domain = domain;}httpcontext.current.response.cookies.add(tokencookie);return;}2、读取cookie
public static string getcookie(){var cookie = httpcontext.current.request.cookies["localtoken"];if (cookie != null)return cookie.value;return string.empty;}3、移出cookie,就是设置cookie过期
public static void removetoken(string username){if (tokenstore != "cookies")redishelper.remove(ssoprefix username);var cookie = httpcontext.current.request.cookies["localtoken"];if (cookie != null){var domain = webconfighelper.getwebconfigvalue("cookiesdomain");if (!string.isnullorwhitespace(domain)){cookie.domain = domain;}cookie.expires = datetime.now.adddays(-1);}return;}
转载于:https://www.cnblogs.com/sanqianjin/p/5426488.html
总结
以上是尊龙游戏旗舰厅官网为你收集整理的c#方式操作cookie的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: