asp.net-core – 使用ASP.NET Core创建cookie
发布时间:2020-12-16 06:34:18 所属栏目:asp.Net 来源:网络整理
导读:在ASP.NET MVC 5中,我有以下扩展名: public static ActionResult Alert(this ActionResult result,String text) { HttpCookie cookie = new HttpCookie("alert") { Path = "/",Value = text }; HttpContext.Current.Response.Cookies.Add(cookie); return r
在ASP.NET MVC 5中,我有以下扩展名:
public static ActionResult Alert(this ActionResult result,String text) { HttpCookie cookie = new HttpCookie("alert") { Path = "/",Value = text }; HttpContext.Current.Response.Cookies.Add(cookie); return result; } 基本上我正在添加一个带文本的cookie. 在ASP.NET Core中,我无法找到创建HttpCookie的方法. 这不可能吗? 解决方法
你尝试过类似的东西:
public static ActionResult Alert(this ActionResult result,Microsoft.AspNetCore.Http.HttpResponse response,string text) { response.Cookies.Append( "alert",text,new Microsoft.AspNetCore.Http.CookieOptions() { Path = "/" } ); return result; } 您可能还必须在调用中将响应传递给控制器??(或从中调用它的任何位置).例如: return Ok().Alert(Response,"Hi"); StackOverflow Reference (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 四种为HttpClient添加默认请求报头的解决方案
- asp.net-mvc – 我的MVC控制器是否真的知道JSON?
- asp.net-mvc – 什么原因导致asp.net无法创建/影子复制错误
- asp.net-mvc – 如何使用Moq模拟存储库Single(Expression>
- 我的团队成员不支持使用asp.net中提供的验证控件(用于Web应
- Asp.net MVC中使用JQuery插件ajaxFileUpload上传文件
- asp.net-mvc – 在ASP.NET MVC中的View和PartialView有什么
- .net – 如何获取客户端DotNetOpenAuth.OAuth2返回的错误消
- asp.net – 如何增加我的存储过程调用的超时时间(见错误)?
- 权限管理学习 一、ASP.NET Forms身份认证
推荐文章
站长推荐
- asp.net – 添加runat =“server”会改变布局的行
- asp.net-mvc – 具有输出参数的ExecuteSqlComman
- ASP.NET Core中Middleware的使用
- asp.net-mvc – 如何调试此错误:’无法找到iise
- asp.net – 有没有比升级到Visual Studio 2010 U
- .net核心中的ServicePointManager.DefaultConnec
- asp.net – log4net在应用程序关闭之前不会写入日
- asp.net-mvc – ASP.NET MVC:如何从Html.Action
- asp.net – Twitter通知ajax吧,他们是怎么做到的
- asp.net – 如何在不使用global.asax的情况下添加
热点阅读