从请求中获取过期cookie的空状态检查。饼干

时间:2017-02-13 08:02:14

标签: jquery asp.net cookies

我尝试了大部分事情来做到这一点。而我找不到解决方案。我尝试了以下的事情

我已将cookie值指定为以下内容,

   HttpCookie cookie = new HttpCookie("CKUserRole");
                cookie.Value = userRoleName;

我需要在jquery中查看条件

if('@HttpContext.Current.Request.Cookies["CKUserRole"].Value'!=null)
{
//But always it is executing and throw the error. 
}

然后我将代码更改为viewdata,如控制器中的以下所示

ViewBag.CKUserRole = userRoleName;

我在jquery中得到这个,

  if ('@Html.Raw(Json.Encode(ViewData["IsSecurityCheck"]))' != null) {

这个也在执行并抛出错误。请建议我做空检查。

1 个答案:

答案 0 :(得分:0)

而不是这样做。

if('@HttpContext.Current.Request.Cookies["CKUserRole"]')
{
//will not throw an error. 
}