Startup.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using HaBookCms.AzureStorage.ServiceExtension;
  6. using Microsoft.AspNetCore.Builder;
  7. using Microsoft.AspNetCore.Hosting;
  8. using Microsoft.AspNetCore.HttpsPolicy;
  9. using Microsoft.AspNetCore.Mvc;
  10. using Microsoft.Extensions.Configuration;
  11. using Microsoft.Extensions.DependencyInjection;
  12. using Microsoft.Extensions.Logging;
  13. using Microsoft.Extensions.Options;
  14. namespace HaBookCms.AzureBlobStorageTest
  15. {
  16. public class Startup
  17. {
  18. public Startup(IConfiguration configuration, IHostingEnvironment env)
  19. {
  20. var builder = new ConfigurationBuilder()
  21. .SetBasePath(env.ContentRootPath)
  22. .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
  23. .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
  24. .AddEnvironmentVariables();
  25. Configuration = builder.Build();
  26. }
  27. public IConfiguration Configuration { get; }
  28. // This method gets called by the runtime. Use this method to add services to the container.
  29. public void ConfigureServices(IServiceCollection services)
  30. {
  31. services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
  32. services.AddAzureBlobStorage().AddConnection(new AzureStorageOptions() {
  33. ConnectionString=Configuration["AppSettings:Azure:StorageConnection"]
  34. });
  35. services.AddAzureTableStorage().AddConnection(new AzureStorageOptions()
  36. {
  37. ConnectionString = Configuration["AppSettings:Azure:StorageConnection"]
  38. });
  39. }
  40. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  41. public void Configure(IApplicationBuilder app, IHostingEnvironment env)
  42. {
  43. if (env.IsDevelopment())
  44. {
  45. app.UseDeveloperExceptionPage();
  46. }
  47. else
  48. {
  49. // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
  50. app.UseHsts();
  51. }
  52. app.UseStaticFiles();
  53. app.UseHttpsRedirection();
  54. app.UseMvc();
  55. }
  56. }
  57. }