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


C# HttpContext.GetTenant方法代码示例

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


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

示例1: GetRequestTokensAsync

        public async Task<AntiforgeryTokenSet> GetRequestTokensAsync(HttpContext httpContext)
        {
            Debug.Assert(httpContext != null);

            //var cookieToken = httpContext.Request.Cookies[_options.CookieName];

            var tenant = httpContext.GetTenant<SiteContext>();
            var cookieToken = httpContext.Request.Cookies[_options.CookieName + tenant.SiteFolderName];

            StringValues requestToken;
            if (httpContext.Request.HasFormContentType)
            {
                // Check the content-type before accessing the form collection to make sure
                // we report errors gracefully.
                var form = await httpContext.Request.ReadFormAsync();
                requestToken = form[_options.FormFieldName];
            }

            // Fall back to header if the form value was not provided.
            if (requestToken.Count == 0 && _options.HeaderName != null)
            {
                requestToken = httpContext.Request.Headers[_options.HeaderName];
            }

            return new AntiforgeryTokenSet(requestToken, cookieToken, _options.FormFieldName, _options.HeaderName);
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:26,代码来源:SiteAntiforgeryTokenStore.cs

示例2: Invoke

 public async Task Invoke(HttpContext httpContext)
 {
     using (_logger.BeginScope("TenantResolverMiddleware"))
     {
         _logger.LogInformation("Starting to get the tenant");
         if (httpContext.Request.Path != new PathString("/"))
         {
             var tenant = httpContext.GetTenant();
             if (tenant == null)
             {
                 tenant = await _tenantResolver.ResolveAsync(httpContext);
                 if (tenant != null)
                 {
                     httpContext.SetTenant(tenant);
                 }
                 else
                 {
                     //httpContext.Response.StatusCode = 404;
                     //return;
                 }
             }
         }
     }
     await _next(httpContext);
 }
开发者ID:SergiyTrygub,项目名称:mynotes,代码行数:25,代码来源:AppTenantMiddleware.cs

示例3: Invoke

        public async Task Invoke(HttpContext context, IMessageService messageService)
        {
            var tenant = context.GetTenant<AppTenant>();

            if (tenant != null)
            {
                await context.Response.WriteAsync(
                    messageService.Format($"Tenant \"{tenant.Name}\"."));
            }
            else
            {
                await context.Response.WriteAsync("No matching tenant found.");
            }
        }
开发者ID:saaskit,项目名称:saaskit,代码行数:14,代码来源:Startup.cs

示例4: GetCookieToken

        public string GetCookieToken(HttpContext httpContext)
        {
            Debug.Assert(httpContext != null);

            //var requestCookie = httpContext.Request.Cookies[_options.CookieName];

            var tenant = httpContext.GetTenant<SiteContext>();

            var requestCookie = httpContext.Request.Cookies[_options.CookieName + tenant.SiteFolderName];

            if (string.IsNullOrEmpty(requestCookie))
            {
                // unable to find the cookie.
                return null;
            }

            return requestCookie;
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:18,代码来源:SiteAntiforgeryTokenStore.cs

示例5: Match

        public bool Match(
            HttpContext httpContext, 
            IRouter route, 
            string routeKey, 
            RouteValueDictionary values, 
            RouteDirection routeDirection)
        {
            string requestFolder = httpContext.Request.Path.StartingSegment();

            var tenant = httpContext.GetTenant<SiteContext>();

            if (tenant != null)
            {
                if (tenant.SiteFolderName == requestFolder) { return true; }

            }

            return false;
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:19,代码来源:SiteFolderRouteConstraint.cs

示例6: IsMatch

        private bool IsMatch(HttpContext context, string path)
        {
            if (context.Request.Path.StartsWithSegments(path)) return true;
            if(multiTenantOptions.Mode == MultiTenantMode.FolderName && !multiTenantOptions.UseRelatedSitesMode)
            {
                var site = context.GetTenant<SiteContext>();
                if(site != null && (!string.IsNullOrEmpty(site.SiteFolderName)))
                {
                    var folderPath = "/" + site.SiteFolderName + path;
                    if (context.Request.Path.StartsWithSegments(folderPath))
                    {
                        var idBasePath = context.GetBasePath().EnsureTrailingSlash();
                        context.SetBasePath(idBasePath + site.SiteFolderName + "/");
                        return true;
                    }
                }
            }

            return false;
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:20,代码来源:MultiTenantEndpointRouter.cs

示例7: SaveCookieToken

        public void SaveCookieToken(HttpContext httpContext, string token)
        {
            Debug.Assert(httpContext != null);
            Debug.Assert(token != null);

            var options = new CookieOptions() { HttpOnly = true };

            // Note: don't use "newCookie.Secure = _options.RequireSSL;" since the default
            // value of newCookie.Secure is poulated out of band.
            if (_options.RequireSsl)
            {
                options.Secure = true;
            }

            //httpContext.Response.Cookies.Append(_options.CookieName, token, options);

            var tenant = httpContext.GetTenant<SiteContext>();
            if (tenant.SiteFolderName.Length > 0) options.Path = new PathString("/" + tenant.SiteFolderName);
            httpContext.Response.Cookies.Append(_options.CookieName + tenant.SiteFolderName, token, options);
        }
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:20,代码来源:SiteAntiforgeryTokenStore.cs


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