protected override Task <BlobEntityResolveResult> GetBlobEntityFromHttpContextOrNullAsync([NotNull] IBlobEntityResolveContext context, [NotNull] HttpContext httpContext) { var result = new BlobEntityResolveResult(); if (httpContext.Request.QueryString.HasValue && httpContext.Request.Query.ContainsKey(BlobEntityResolverConsts.EntityTypeKey) && httpContext.Request.Query.ContainsKey(BlobEntityResolverConsts.EntityIdKey)) { result.EntityType = httpContext.Request.Query[BlobEntityResolverConsts.EntityTypeKey].ToString(); result.EntityId = httpContext.Request.Query[BlobEntityResolverConsts.EntityIdKey].ToString(); return(Task.FromResult(result)); } return(Task.FromResult(result)); }
public virtual async Task <BlobEntityResolveResult> ResolveBlobEntityAsync() { var result = new BlobEntityResolveResult(); using (var serviceScope = _serviceProvider.CreateScope()) { var context = new BlobEntityResolveContext(serviceScope.ServiceProvider); foreach (var tenantResolver in _options.BlobEntityResolvers) { await tenantResolver.ResolveAsync(context); if (context.HasResolvedTenantOrHost()) { result.EntityType = context.EntityType; result.EntityId = context.EntityId; break; } } } return(result); }
protected override Task <BlobEntityResolveResult> GetBlobEntityFromHttpContextOrNullAsync([NotNull] IBlobEntityResolveContext context, [NotNull] HttpContext httpContext) { var result = new BlobEntityResolveResult(); try { //StreamReader stream = new StreamReader(httpContext.Request.Body); //string body = stream.ReadToEnd(); //httpContext.Request.EnableBuffering(); using (var reader = new StreamReader(httpContext.Request.Body, System.Text.Encoding.UTF8)) { reader.BaseStream.Seek(0, SeekOrigin.Begin); //大概是== Request.Body.Position = 0;的意思 var readerStr = reader.ReadToEndAsync().Result; var input = Newtonsoft.Json.JsonConvert.DeserializeObject <SaveBytesInput>(readerStr); result.EntityType = input?.EntityType; result.EntityId = input?.EntityId; } } catch (Exception ex) { } return(Task.FromResult(result)); }