public ContentResult CreatCard() { Response.ContentType = "application/json"; ResultInfo <Card> result; try { if (Request.Cookies["CardId"] != null) { throw new Exception("已有公交卡,不可重复创建,请先删除现有公交卡"); } Card card = CardOperation.CreatCard(); result = new ResultInfo <Card>(ResultInfoEnum.OK, "访问成功", Request.Url.ToString(), card); HttpCookie cookie = new HttpCookie("CardId") { Value = card.CardId, Expires = DateTime.MaxValue }; Response.Cookies.Add(cookie); return(Content(JsonConvert.SerializeObject(result))); } catch (Exception e) { result = result = new ResultInfo <Card>(ResultInfoEnum.ERROR, e.Message, Request.Url.ToString(), null); return(Content(JsonConvert.SerializeObject(result))); } }