Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.HttpsPolicy;
  8. using Microsoft.AspNetCore.Mvc;
  9. using Microsoft.Extensions.Configuration;
  10. using Microsoft.Extensions.DependencyInjection;
  11. using Microsoft.Extensions.Hosting;
  12. using Microsoft.Extensions.Logging;
  13.  
  14. namespace CORS_TEST
  15. {
  16. public class Startup
  17. {
  18. public Startup(IConfiguration configuration)
  19. {
  20. Configuration = configuration;
  21. }
  22.  
  23. readonly string SpecificAllowedOrigins = "SpecificAllowedOrigins";
  24.  
  25. public IConfiguration Configuration { get; }
  26.  
  27. // This method gets called by the runtime. Use this method to add services to the container.
  28. public void ConfigureServices(IServiceCollection services)
  29. {
  30. services.AddCors(options =>
  31. {
  32. options.AddPolicy(SpecificAllowedOrigins,
  33. builder =>
  34. {
  35. builder.AllowAnyOrigin()
  36. .AllowAnyHeader()
  37. .AllowAnyMethod();
  38. });
  39. });
  40.  
  41. services.AddControllers();
  42. }
  43.  
  44. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  45. public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
  46. {
  47. if (env.IsDevelopment())
  48. {
  49. app.UseDeveloperExceptionPage();
  50. }
  51.  
  52. app.UseCors(SpecificAllowedOrigins);
  53.  
  54. //app.UseHttpsRedirection();
  55.  
  56. app.UseRouting();
  57.  
  58. app.UseAuthorization();
  59.  
  60. app.UseEndpoints(endpoints =>
  61. {
  62. endpoints.MapControllers();
  63. });
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement