Пример #1
0
        public static ControllerContext GetMockedControllerContext()
        {
            var controllerContext = new Mock <ControllerContext>();

            var req      = new MockHttpRequest();
            var session  = new MockHttpSession();
            var identity = new FlowTasksPrincipal(new FlowTasksIdentity("cgrant", ""));

            controllerContext.SetupGet(a => a.HttpContext.User).Returns(identity);
            controllerContext.SetupGet(a => a.HttpContext.Request).Returns(req);
            controllerContext.SetupGet(a => a.HttpContext.Session).Returns(session);

            return(controllerContext.Object);
        }
Пример #2
0
        protected void Application_AuthenticateRequest(Object sender, EventArgs e)
        {
            HttpCookie authCookie = Request.Cookies[
                FormsAuthentication.FormsCookieName];

            if (authCookie != null)
            {
                //Extract the forms authentication cookie
                FormsAuthenticationTicket authTicket =
                    FormsAuthentication.Decrypt(authCookie.Value);

                FlowTasksIdentity  id   = new FlowTasksIdentity(authTicket.Name, authTicket.UserData);
                FlowTasksPrincipal user = new FlowTasksPrincipal(id);
                Context.User = user;

                /*
                 * When you are going to use the information later, you can access your custom principal as follows.
                 *   (CustomPrincipal)this.User
                 * or
                 *   (CustomPrincipal)this.Context.User
                 */
            }
        }