Copied to clipboard

Flag this post as spam?

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


  • wolulcmit 357 posts 693 karma points
    Dec 11, 2012 @ 09:14
    wolulcmit
    0

    Setting a cookie from a hyperlink in Razor?

    Am currently trying to replicate some behaviour that I'm accomplishing via jquery and the cookie plugin.
    Anyone know how the same could be acheived with razor?

    for simplicity sake, could I cut javascript out of the equation and acheive the same with Razor?
    I know how to read cookie values in Razor but not sure about how to set them

        $("#mylink").click(function(){
            $.cookie('justalonleycookie', 'true', { expires: 20, path: '/' });
            location.reload();
        });

    thanks muchly

    - Tim

     

     

     

  • Mike Chambers 636 posts 1253 karma points c-trib
    Dec 11, 2012 @ 10:33
    Mike Chambers
    100
    if (Request.Cookies[cookie] != null)
                    {
                        HttpCookie newCookie = new HttpCookie(cookie);
                        newCookie.Domain = "." + HttpContext.Current.Request.Url.Host;
                        newCookie.Expires = DateTime.Now.AddDays(1);
                        Response.Cookies.Add(newCookie);
                    }

    something like this, and either hook up via ajax request, querystring url or look for the isPost from a submit button...

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies