oktatas:programozas:csharp:dotnetcore:web_api:cross-origin
Ez a dokumentum egy előző változata!
Tartalomjegyzék
Cross-origin kérés
- Szerző: Sallai András
- Copyright © 2024, Sallai András
- Szerkesztve: 2024
- Licenc: CC BY-SA 4.0
- Web: https://szit.hu
Engedélyezés
var origin = "*"; builder.Services.AddCors(options => { options.AddPolicy(name: origin, policy => { policy .AllowAnyMethod() .AllowAnyHeader() .WithOrigins("http://localhost:4200"); }); }); //... app.UseCors(origin);
Teljes Program.cs
- Program.cs
using Microsoft.EntityFrameworkCore; using jarmu; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); //Adatbázis builder.Services.AddDbContext<DataService>(options => { var connectionString = builder.Configuration.GetConnectionString("Mariadb"); options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)); }); var origin = "*"; builder.Services.AddCors(options => { options.AddPolicy(name: origin, policy => { policy .AllowAnyMethod() .AllowAnyHeader() .WithOrigins("http://localhost:4200"); }); }); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseCors(origin); app.UseAuthorization(); app.MapControllers(); app.Run();
Linkek
oktatas/programozas/csharp/dotnetcore/web_api/cross-origin.1709695201.txt.gz · Utolsó módosítás: 2024/03/06 04:20 szerkesztette: admin