Copied to clipboard

Flag this post as spam?

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


  • Galina 44 posts 258 karma points
    Apr 01, 2015 @ 16:14
    Galina
    0

    Backoffice cluster: angular-cookie didn't create

    Hello.

    I want to use Umbraco backoffice as cluster. I wrote in web.config

    <sessionState cookieless="false" mode="StateServer" stateConnectionString="tcpip=myserver:42424" timeout="60" useHostingIdentity="false"/>

    but after that angular.js don't create cookie XSRF-TOKEN and XSRF-V and there are no link to application section (content, media, settings and so on) and asmx-webservices (I need them a lot, not webapi, I need asmx) work correctly.

    But if i turn cookieless="true" Umbraco looks good and work fine with SessionID in URL, but asmx-webservices with contentType=application/json (it's jquery ajax postback) didn't work at all because it can't redirect from /json/myservice.asmx/method to /json/(SessionId)/myservice.asmx/method

    Does somebody use Umbraco with state server? How does it work?

  • Galina 44 posts 258 karma points
    Apr 03, 2015 @ 12:44
    Galina
    100

    Hello. If somebody will be confronted with such difficulty, there is a workaround:

    AppCode:

    namespace UmbracoCMS.AppCode
    {
        public class MyUmbracoApplication : Umbraco.Web.UmbracoApplication
        {
            protected void Session_Start(object sender, EventArgs e)
            {
                string cookieToken, headerToken;
                AngularAntiForgeryHelper.GetTokens(out cookieToken, out headerToken);
    
                CommonManager.AddCookie(AngularAntiForgeryHelper.AngularCookieName, headerToken);
                CommonManager.AddCookie(AngularAntiForgeryHelper.CsrfValidationCookieName, cookieToken);
            }
        }
    }
    <%@ Application Codebehind="Global.asax.cs" Inherits="UmbracoCMS.AppCode.MyUmbracoApplication" Language="C#" %>
    namespace UmbracoCMS.AppCode
    {
        public static class CommonManager
        {public static void AddCookie(string cookieName, string cookieValue)
            {
                AddCookie(cookieName, cookieValue, GlobalSettings.UseSSL);
            }
    
            public static void AddCookie(string cookieName, string cookieValue, bool secure, string path = "/", bool httpOnly = false)
            {
                var cookie = new HttpCookie(cookieName, cookieValue) {
                    Path = path,
                    HttpOnly = httpOnly,
                    Secure = secure
                };
                if (HttpContext.Current.Request.Cookies[cookieName] != null) {
                    HttpContext.Current.Response.SetCookie(cookie);
                } else {
                    HttpContext.Current.Response.AppendCookie(cookie);
                }
            }
        }
    }

    It creates angular cookie.

Please Sign in or register to post replies

Write your reply to:

Draft