Tôi đang cố gắng lấy ID người dùng được lưu trữ trong cookie thông qua tệp Bộ điều khiển chung mà tôi có thể truy cập trong toàn bộ trang web.Làm cách nào để truy cập vào Request.cookies trong bộ điều khiển ASP.NET MVC?
Tôi đã tạo ra FunctionsController
như một bộ điều khiển, với nội dung như sau:
public static int loggedinUser()
{
return Convert.ToInt32( request.Cookies["userid"].Value);
}
Tôi không thể yêu cầu bất kỳ mục Cookie ngay cả khi tôi đã cố gắng với:
HttpRequestBase request = controllerContext.HttpContext.Request;
nó nói Một tham chiếu đối tượng là cần thiết cho các phi trường tĩnh, phương pháp, hoặc tài sản 'System.Web.Mvc.Controller.Request.get' –
sử dụng System; using System.Collections.Generic; using System.Linq; using ystem.Web; using System.Web.Mvc; using CRM.Models; không gian tên MarcelCRM.Controllers {public class FunctionsController: Controller {\t public static int loggedinUser() {return Convert.ToInt32 (Request.Cookies ["someCookie"]); \t}}} –