예제 #1
0
        protected void Session_Start()
        {
            if (Context.Session != null)
            {
                if (Context.Session.IsNewSession)
                {
                    string sCookieHeader = Request.Headers["Cookie"];
                    if ((null != sCookieHeader) && (sCookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                    {
                        //intercept current route
                        HttpContextBase currentContext = new HttpContextWrapper(HttpContext.Current);
                        RouteData       routeData      = RouteTable.Routes.GetRouteData(currentContext);
                        Response.Redirect("~/Home/SessionTimeout");
                        Response.Flush();
                        Response.End();
                    }
                }
            }

            //set session culture using DefaultCulture key
            IoCFactory.Container.StartSessionLevelContainer();
            Session.ApplyCulture(AppConfiguration.DefaultCulture);

            ITenantResolver tenantResolver = IoCFactory.Container.Resolve <ITenantResolver>();
            Tenant          tenant         = tenantResolver.Resolve(this.Request);

            // if the tenant has no landing page, set the application's default landing page for it.
            GeneralSettings generalSettings = IoCFactory.Container.Resolve <GeneralSettings>();
            var             landingPage     = generalSettings.GetEntryValue("landingPage").ToString();

            tenant.LandingPage = landingPage; // checks and sets

            this.Session.SetTenant(tenant);
        }
예제 #2
0
        public ActionResult Index()
        {
            ViewBag.Title = PresentationModel.GetViewTitleForTenant("Home", this.Session.GetTenant());

            // here there are 2 cases to consider.
            // 1.no user->landingpage
            // 2.user logged into landingpage for users
            Tuple <string, string, string> landingPage = null;

            //check if user exist
            if (!string.IsNullOrEmpty(HttpContext.User?.Identity?.Name)) //user
            {
                // User exist : load ladingpage for users
                GeneralSettings generalSettings     = IoCFactory.Container.Resolve <GeneralSettings>();
                var             landingPageForUsers = generalSettings.GetEntryValue("landingPageForUsers").ToString();

                if (landingPageForUsers.Split(',').Length == 3)//check wheter 3 values exist for teh action
                {
                    landingPage = new Tuple <string, string, string>(
                        landingPageForUsers.Split(',')[0].Trim(),  //module id
                        landingPageForUsers.Split(',')[1].Trim(),  //controller
                        landingPageForUsers.Split(',')[2].Trim()); //action
                }
            }
            else
            {
                landingPage = this.Session.GetTenant().LandingPageTuple;
            }

            //if the landingPage not null and the action is accessable
            if (landingPage == null || !this.IsAccessible(landingPage.Item1, landingPage.Item2, landingPage.Item3))
            {
                return(View());
            }

            var result = this.Render(landingPage.Item1, landingPage.Item2, landingPage.Item3);



            return(Content(result.ToHtmlString(), "text/html"));
        }
예제 #3
0
        /// <summary>
        /// creates a httpcontxt with an authenticated user
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public ControllerContext BuildHttpContext(string userName)
        {
            if (!app.Started)
            {
                throw new System.InvalidOperationException("The test environmnet has not been started yet. call app.Start(...) before calling this method.");
            }

            var httpCtxMock = new Mock <HttpContextBase>();

            ITenantResolver tenantResolver = IoCFactory.Container.Resolve <ITenantResolver>();
            var             tenant         = tenantResolver.DefaultTenant;

            // setting the landing page for the current session
            GeneralSettings generalSettings = IoCFactory.Container.Resolve <GeneralSettings>();
            var             landingPage     = generalSettings.GetEntryValue("landingPage").ToString();

            tenant.LandingPage = landingPage; // checks and sets

            var httpSessionMock = new Mock <HttpSessionStateBase>();

            httpSessionMock.Setup(x => x["CurrentTenant"]).Returns(tenant);
            httpCtxMock.Setup(ctx => ctx.Session).Returns(httpSessionMock.Object);

            if (!string.IsNullOrWhiteSpace(userName))
            {
                var validPrincipal = new ClaimsPrincipal(
                    new[]
                {
                    new ClaimsIdentity(
                        new[] { new Claim(ClaimTypes.NameIdentifier, userName) })
                });
                httpCtxMock.Setup(ctx => ctx.User).Returns(validPrincipal);
            }

            ControllerContext controllerCtx = new ControllerContext();

            controllerCtx.HttpContext = httpCtxMock.Object;
            return(controllerCtx);
        }