C
C#5mo ago
IcyIme

✅ asp.net web api connection refused

i have problem with web api its writing me a connection refused
csharp
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using UniCademy.server.Data;
using UniCademy.server.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddDbContext<IdentityDbContext>(option =>
option.UseNpgsql(builder.Configuration.GetConnectionString("idenitycs")));


builder.Services.AddIdentityApiEndpoints<IdentityUser>().
AddRoles<IdentityRole>().
AddEntityFrameworkStores<IdentityDbContext>();

builder.Services.AddScoped<IRoleService, RoleService>();

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option =>
{
option.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
In = Microsoft.OpenApi.Models.ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
option.OperationFilter<SecurityRequirementsOperationFilter>();
});
builder.Services.AddCors(option => option.AddPolicy("wasm",
policy => policy.WithOrigins(builder.Configuration["BackendUrl"] ?? "",
builder.Configuration["FrontendUrl"] ?? "")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
));
var app = builder.Build();
app.MapIdentityApi<IdentityUser>();

app.UseCors("wasm");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
csharp
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;
using UniCademy.server.Data;
using UniCademy.server.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddDbContext<IdentityDbContext>(option =>
option.UseNpgsql(builder.Configuration.GetConnectionString("idenitycs")));


builder.Services.AddIdentityApiEndpoints<IdentityUser>().
AddRoles<IdentityRole>().
AddEntityFrameworkStores<IdentityDbContext>();

builder.Services.AddScoped<IRoleService, RoleService>();

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option =>
{
option.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
{
In = Microsoft.OpenApi.Models.ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey
});
option.OperationFilter<SecurityRequirementsOperationFilter>();
});
builder.Services.AddCors(option => option.AddPolicy("wasm",
policy => policy.WithOrigins(builder.Configuration["BackendUrl"] ?? "",
builder.Configuration["FrontendUrl"] ?? "")
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()
));
var app = builder.Build();
app.MapIdentityApi<IdentityUser>();

app.UseCors("wasm");
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server