Search code examples
cookiesasp.net-mvc-2creation

Where should I create and get the value of a Cookie which I will be using for my ASP.NET MVC Application?


EDIT : I have another problem..Now I want to get the cookies value...in controllers constructor...does not allow me to do that since HttpRequest is Null...I dont want to do it on every controller action...since want to do it only once...and then every action can access cookie value

ORIGINAL : Hi all I want to create a cookie for the each of the users of my my asp.net mvc 2.0 application. So I tried creating in Application_Start() of the global.asax. But it does not have access to Response object. Actually there is not a common or index page that will be hit all the time and hence I am not able to do it on some landing page/view. Can anyone suggest me where I can create a cookie?


Solution

  • You should be able to use the Application_BeginRequest event in your global.asax, this event is triggered when any page is requested.