I’m experimenting with an ASP.NET MVC 3 site, using razor as the view-engine. I need to assign a cookie to every visitor of my site. What would be the best place/way to do this?
Please elaborate, because I’m very new at ASP.NET.
I’m experimenting with an ASP.NET MVC 3 site, using razor as the view-engine. I
Share
There are 3 ways to implement it without breaking mvc pattern:
1 – Base controller class with specified behaviour at
OnActionExecuting/OnActionExecuted/OnResultExecutingmethod (if this behavior is necessary across the entire web site)2 – Create action filter with specified behaviour at
OnActionExecuting/OnActionExecuted/OnResultExecutingmethods:and
assign filter attribute to some controllers/actions (if this behavior is not necessary for all web site), for example
or
3 – Create action filter with specified behaviour at
OnActionExecuting/OnActionExecuted/OnResultExecutingmethods and register it atglobal.asax– it will work for all actions of all controllers (if this behavior is necessary for all web site)I don’t recommend to use Base Controller way, because it less extensible than Global Filter way. Use different global filters for providing different independent global behaviors.