views:

85

answers:

1

Hi,

in my .net mvc application, I am overriding the Controller class and creating my own that I will inherit from for all my controllers.

Which event should I check for a cookie in?

Does OnActionExecuting make sense?

I tried OnActionExecuting, but can't seem to find the cookie collection?

HttpCookie myCookie = ????????????
+1  A: 

Yes, you can check cookies in OnActionExecuting(). It is very easy:

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    HttpCookieCollection cookies = Request.Cookies;

    // Check your cookies:

    bool yourCookieExistsInRequest = cookies["YourCookie"] != null;

    HttpCookie yourCookie = cookies["YourCookie"];

    base.OnActionExecuting(filterContext);
}
eu-ge-ne