So, I’m trying to use the cookie plugin (seen here: http://grails.org/plugin/cookie), and overall, it’s working pretty well. However I’m running into issues accessing my cookie from different parts of the app, due to path problems.
I’m getting identical cookies stored in different places depending on where in the app I am.
I’ve added this to my Config.groovy, as suggested by the plugin page:
com.studentuniverse.grails.plugins.cookie.services.CookieService.metaClass.setCookie = { response, name, value, maxAge ->
def cookie = new javax.servlet.http.Cookie(name, value)
cookie.setMaxAge(maxAge)
cookie.setPath("/")
response.addCookie(cookie)
}
But that doesn’t seem to change anything. I still get two cookies, one stored at /[AppName]/[Controller1] and the other at /[AppName]/[Controller2]. Ideally, I’d like both to just be stored at /[AppName]. However, any changes I make to the setPath variable seem to have no effect. I’ve even tried changing it to
cookie.setPath("/cookies")
anticipating that it would be stored at /[AppName]/[Controller1]/cookies , for example, but no change was made. Do I need to pass in the path variable somewhere else, or modify that path in a different way?
Have you tried adding domain.
Here is my code and it works fine