本文整理汇总了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);
}
示例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);
}
示例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.");
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}