Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damon 217 posts 287 karma points
    Aug 18, 2015 @ 15:11
    Damon
    1

    Want to create cookie and store values to it

    Hi,

    I am using Umbraco 7. I want to create a cookie and store stuff to it relating to each page visited.

    To do this, do I need to intercept/hijack every request because it is using MVC? Does the cookie code need to go in the controller?

    Or can this be done in the view?

    Kind Regards,

  • Ryios 122 posts 263 karma points
    Aug 18, 2015 @ 15:33
    Ryios
    2

    You can hijack every request in umbraco by specifying your own controller as the default controller.

    Refer to this documentation here.

    Scroll down to "Change the default controller".

    Make sure your controller derives from "RenderMvcController" in the Umbraco.Web.Mvc namespace.

    Now, the Index method is what runs on every front end umbraco page... If you override that and don't call the base you will effectively stop umbraco from rendering the pages..

    However you can override index and do your cookie logic, just make sure you return "base.Index(model)" when you are done.

    In my opinion, this is the best way to do what you want... You could make an HttpModule and register it before UmrbacoModule in the web.config, but that would perform like crap and is unnecessary and overkill.

Please Sign in or register to post replies

Write your reply to:

Draft