public HttpResponseMessage Process() { FileSystemCommand command; Enum.TryParse(CurrentContext.Request["command"], out command); string arguments = CurrentContext.Request["arguments"]; AzureStorageAccount account = AzureStorageAccount.FileManager.Value; var provider = new AzureBlobFileProvider(account.AccountName, account.AccessKey, account.ContainerName, TempDirectoryPath); var config = new FileSystemConfiguration { Request = new HttpContextWrapper(CurrentContext).Request, FileSystemProvider = provider, //uncomment the code below to enable file/folder management //AllowCopy = true, //AllowCreate = true, //AllowMove = true, //AllowDelete = true, //AllowRename = true, //AllowUpload = true, AllowDownload = true, UploadConfiguration = new UploadConfiguration { MaxFileSize = 1048576 }, TempDirectory = TempDirectoryPath }; var processor = new FileSystemCommandProcessor(config); var commandResult = processor.Execute(command, arguments); var result = commandResult.GetClientCommandResult(); return(command == FileSystemCommand.Download && commandResult.Success ? CreateDownloadResponse(result) : Request.CreateResponse(result)); }
public void ConfigureServices(IServiceCollection services) { AzureBlobOptions blobOptions = Configuration.GetSection("AzureBlobOptions").Get <AzureBlobOptions>(); AzureBlobFileProvider azureBlobFileProvider = new AzureBlobFileProvider(blobOptions); services.AddSingleton(azureBlobFileProvider); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { //options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(actions => { actions.IdleTimeout = TimeSpan.FromSeconds(10); actions.Cookie.HttpOnly = true; }); services.AddMvc(); services.AddHttpContextAccessor(); services.AddDbContext <MusicStoreEntities>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("MusicStoreEntities"))); services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme) .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options)).AddCookie(); var blobOptions = new AzureBlobOptions { ConnectionString = Configuration.GetConnectionString("AzureStorageStaticFiles"), DocumentContainer = "wwwroot" }; var azureBlobFileProvider = new AzureBlobFileProvider(blobOptions); services.AddSingleton(azureBlobFileProvider); }
/// <summary> /// Конфигурация загружается из переменных окружения /// И из Azure Storage если заданы переменные окружения /// ConfigStorageUri /// ConfigStorageSas /// ConfigStorageContainer /// /// или из файла appsettings.local.json если переменные не заданы /// </summary> /// <param name="builder"></param> public override void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder) { FunctionsHostBuilderContext context = builder.GetContext(); //Get enviroment variables for config file access var configStorage = new ConfigStorageAccess(); if (!configStorage.Configured) { builder.ConfigurationBuilder .AddJsonFile(Path.Combine(context.ApplicationRootPath, ConfigFileNameLocal), false, false) .AddEnvironmentVariables(); } else { CheckConfigurationBlob(configStorage).Wait(); var azureBlobFileProvider = new AzureBlobFileProvider(new AzureBlobOptions() { ConnectionString = configStorage.ConnectionString, DocumentContainer = configStorage.ContainerName }); builder.ConfigurationBuilder .AddJsonFile(azureBlobFileProvider, ConfigFileName, false, false) .AddEnvironmentVariables(); } }
public FileBrowserModel(IContentRepository contentRepository, AzureBlobFileProvider azureBlobFileProvider, IBlobContainerFactory blobContainerFactory) { _contentRepository = contentRepository; _azureBlobFileProvider = azureBlobFileProvider; _blobContainerFactory = blobContainerFactory; var httpContext = ServiceLocator.Current.GetInstance <IHttpContextAccessor>().HttpContext; httpContext.Items.Add("Area", "EZMS"); BasePath = azureBlobFileProvider.DocumentContainer; }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { //options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(actions => { actions.IdleTimeout = TimeSpan.FromSeconds(10); actions.Cookie.HttpOnly = true; }); services.AddMvc(); services.AddHttpContextAccessor(); services.AddDbContext <MusicStoreEntities>(options => options .UseLazyLoadingProxies() .UseSqlServer(Configuration.GetConnectionString("MusicStoreEntities"))); services.AddDbContext <ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ASPNETDB"))); services.AddIdentity <ApplicationUser, IdentityRole>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddAuthentication().AddCookie(); services.ConfigureApplicationCookie(options => { options.LoginPath = "/Account/Logon"; options.ExpireTimeSpan = TimeSpan.FromHours(1); }); var blobOptions = new AzureBlobOptions { ConnectionString = Configuration.GetConnectionString("AzureStorageStaticFiles"), DocumentContainer = "wwwroot" }; var azureBlobFileProvider = new AzureBlobFileProvider(blobOptions); services.AddSingleton(azureBlobFileProvider); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } AzureBlobFileProvider blobFileProvider = app.ApplicationServices.GetRequiredService <AzureBlobFileProvider>(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = blobFileProvider, RequestPath = "/files" }); app.UseDirectoryBrowser(new DirectoryBrowserOptions { FileProvider = blobFileProvider, RequestPath = "/files" }); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.Configure <CookiePolicyOptions>(options => { //options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddSession(actions => { actions.IdleTimeout = TimeSpan.FromMinutes(20); actions.Cookie.HttpOnly = true; }); services.AddDistributedRedisCache(o => { o.Configuration = Configuration.GetConnectionString("RedisCache"); }); services.AddMvc().AddJsonOptions(opt => { opt.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; opt.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; }); services.AddHttpContextAccessor(); services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme) .AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options)).AddCookie(); var blobOptions = new AzureBlobOptions { ConnectionString = Configuration.GetConnectionString("AzureStorageStaticFiles"), DocumentContainer = "wwwroot" }; var azureBlobFileProvider = new AzureBlobFileProvider(blobOptions); services.AddSingleton(azureBlobFileProvider); }
public FileManagerAzureProviderApiController(IHostingEnvironment hostingEnvironment, AzureBlobFileProvider azureFileProvider) { HostingEnvironment = hostingEnvironment; AzureFileProvider = azureFileProvider ?? throw new ArgumentNullException(nameof(azureFileProvider)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { #region Add CORS services.AddCors(options => options.AddPolicy("Cors", builder => { builder .AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); #endregion #region Add Authentication var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"])); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(config => { config.RequireHttpsMetadata = false; config.SaveToken = true; config.TokenValidationParameters = new TokenValidationParameters() { IssuerSigningKey = signingKey, ValidateAudience = true, ValidAudience = this.Configuration["Tokens:Audience"], ValidateIssuer = true, ValidIssuer = this.Configuration["Tokens:Issuer"], ValidateLifetime = true, ValidateIssuerSigningKey = true }; }); #endregion var blobOptionsTracks = new AzureBlobOptions { ConnectionString = Configuration.GetConnectionString("BlobConnectionString"), DocumentContainer = "tracks" }; var azureBlobFileProviderTracks = new AzureBlobFileProvider(blobOptionsTracks); // services.AddSingleton(azureBlobFileProviderTracks); var blobOptionsImages = new AzureBlobOptions { ConnectionString = Configuration.GetConnectionString("BlobConnectionString"), DocumentContainer = "images" }; var azureBlobFileProviderImages = new AzureBlobFileProvider(blobOptionsImages); //services.AddSingleton(azureBlobFileProviderImages); var composite = new CompositeFileProvider(azureBlobFileProviderTracks, azureBlobFileProviderImages); services.AddSingleton(composite); services.AddMvc() .AddJsonOptions( options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" }); }); }