当前位置: 首页>>代码示例>>C#>>正文


C# HttpContextWrapper.RenewUmbracoAuthTicket方法代码示例

本文整理汇总了C#中System.Web.HttpContextWrapper.RenewUmbracoAuthTicket方法的典型用法代码示例。如果您正苦于以下问题:C# HttpContextWrapper.RenewUmbracoAuthTicket方法的具体用法?C# HttpContextWrapper.RenewUmbracoAuthTicket怎么用?C# HttpContextWrapper.RenewUmbracoAuthTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpContextWrapper的用法示例。


在下文中一共展示了HttpContextWrapper.RenewUmbracoAuthTicket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AuthenticateRequest

        /// <summary>
        /// Authenticates the request by reading the FormsAuthentication cookie and setting the 
        /// context and thread principle object
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void AuthenticateRequest(object sender, EventArgs e)
        {
            var app = (HttpApplication) sender;
            var http = new HttpContextWrapper(app.Context);

            //we need to determine if the path being requested is an umbraco path, if not don't do anything
            var settings = UmbracoSettings.GetSettings();

            var backOfficeRoutePath = string.Concat(settings.UmbracoPaths.BackOfficePath, "/");
            var installerRoutePath = string.Concat("Install", "/");

            var routeUrl = "";
            var routeData = RouteTable.Routes.GetRouteData(http);
            if (routeData != null)
            {
                var route = routeData.Route as Route;
                if (route != null)
                {
                    routeUrl = route.Url;
                }
            }

            if (routeUrl.StartsWith(installerRoutePath, StringComparison.InvariantCultureIgnoreCase) ||
                routeUrl.StartsWith(backOfficeRoutePath, StringComparison.InvariantCultureIgnoreCase))
            {
                if (app.Context.User == null)
                {
                    if (app.User != null)
                    {
                        //set the principal object
                        app.Context.User = app.User;
                        Thread.CurrentPrincipal = app.User;
                    }
                    else
                    {
                        var ticket = http.GetUmbracoAuthTicket();
                        if (ticket != null && !ticket.Expired && http.RenewUmbracoAuthTicket())
                        {
                            //create the Umbraco user identity 
                            var identity = new UmbracoBackOfficeIdentity(ticket);

                            //set the principal object
                            var principal = new GenericPrincipal(identity, identity.Roles);
                            app.Context.User = principal;
                            Thread.CurrentPrincipal = principal;
                        }
                    }
                }

            }

        }
开发者ID:Joebeazelman,项目名称:rebelcmsxu5,代码行数:58,代码来源:BackOfficeAuthenticationModule.cs


注:本文中的System.Web.HttpContextWrapper.RenewUmbracoAuthTicket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。