tags:

views:

575

answers:

2

Hi,

I am new to MVC pattern, trying to get Userid stored in cookies via common controller file, which I can access throughout the site.

I have FunctionsController as a controller with content as follows.

public static int loggedinUser() { return Convert.ToInt32( request.Cookies["userid"].Value); }

I am unable to request any cookies items even if I tried with

HttpRequestBase request = controllerContext.HttpContext.Request;

Please guide me. Thanks Anil

+2  A: 

I don't have a problem accessing cookies in ASP.NET MVC using a standard access statement such as:

Request.Cookies["someCookie"]

Your sample had a lower-cased "r" in "request.Cookies". Could that be your problem?

Ian Suttle
it says An object reference is required for the non-static field, method, or property 'System.Web.Mvc.Controller.Request.get'
ANIL MANE
using System;using System.Collections.Generic;using System.Linq;using ystem.Web;using System.Web.Mvc;using CRM.Models;namespace MarcelCRM.Controllers{ public class FunctionsController : Controller { public static int loggedinUser() {return Convert.ToInt32(Request.Cookies["someCookie"]); }}}
ANIL MANE
A: 

Yeah it worked. :)

Thanks a lot

ANIL MANE