Copied to clipboard

Flag this post as spam?

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


  • John C Scott 473 posts 1183 karma points
    Feb 06, 2015 @ 12:34
    John C Scott
    0

    cookie contour_xxxxxxxxx

    A customer is requesting that the cookie which is set is marked as secure as we're serving all the pages from https. 

    Is there any way of making this possible?

    Using Contour 3.0.21 with Umbraco 6.1.6

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Feb 09, 2015 @ 16:50
    Tim
    100

    Hi John!

    There's some info on this stack overflow page that might help you: http://stackoverflow.com/questions/5978667/how-to-secure-the-asp-net-sessionid-cookie it'll require a bit of coding, but it should work without needing to have anything changed in Contour (hopefully).

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 10:14
    John C Scott
    0

    Hi Tim,

    I'd look at that page before, but you posting this again made me look at it again. It looks like this could work. However when I look in the global.asax page I see 

    <%@ Application Codebehind="Global.asax.cs" Inherits="Umbraco.Web.UmbracoApplication" Language="C#" %>

    Which suggests to me that Umbraco is already doing *something* in the global.asax, Im going to have a look at the source now and see if I could may be duplicate it and change the inheritence in this file. Or is there another way to register this within Umbraco? 

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 14:28
    John C Scott
    1

    Yes that worked!

    I had to create a new DLL including system.web & umbraco & umbraco.core with this class

    using System;
    using System.Web;
    
    namespace SecureCookies
    {
        public class Global : Umbraco.Web.UmbracoApplication
        {
          public void Init(HttpApplication application)
          {
              application.EndRequest += (new EventHandler(this.Application_EndRequest));
          }
    
          private void Application_EndRequest(object sender, EventArgs e)
          {
              if (Response.Cookies.Count > 0)
                {
                    foreach (string s in Response.Cookies.AllKeys)
                    {
                             Response.Cookies[s].Secure = true;
                             Response.Cookies[s].HttpOnly = true;
                    }
                }
          }
    
        }
    }

    which was compiled into a dll project as SecureCookies.dll

    and then update the global.asax to

    <%@ Application Codebehind="Global.asax.cs" Inherits="SecureCookies.Global" Language="C#" %>

     

    Worked an absolute treat - thank you for making me look at that approach again. Thanks Tim.

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Feb 12, 2015 @ 14:33
    Tim
    0

    Awesome! Glad it helped :)

  • John C Scott 473 posts 1183 karma points
    Feb 12, 2015 @ 16:11
    John C Scott
    0

    put the source code here:

    https://github.com/johncscott/uSecureCookies

    half thinking about making a package

    not sure how useful it would be

     

Please Sign in or register to post replies

Write your reply to:

Draft