restingphantom
restingphantom
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
thanks for the help though
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
it auto implements from envoirement.dev instead of just envoirenment
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
No description
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
I found it already
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
I didnt even notice that
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
thats where my api is when running loccally!?
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
at least I believe them to be, because i unfortionately dont have access to them
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
The front-end is hosted somewhere else, the env variables during production are https://HOST.net and http://HOST.net
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
the CORS error dont occur in my dev env. only in production
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
C#
global using HTXL_Back_end.Models;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;

var corsPolicy = "CorsPolicy";

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

// Authentication
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey =
new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(builder.Configuration.GetSection("AppSettings:Token").Value!)),
ValidateIssuer = false,
ValidateAudience = false
};
});

// CORS
builder.Services.AddCors(options =>
options.AddPolicy(corsPolicy, policy => policy
.WithOrigins(builder.Configuration.GetSection("AppSettings:AllowedOrigins").Get<string[]>()!)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()));

builder.Services.AddDbContext<HTXLPortfolioContext>();

var app = builder.Build();

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

app.UseCors(corsPolicy);

app.UseHttpsRedirection();

app.UseAuthentication();

app.UseAuthorization();

app.MapControllers();

app.Run();
C#
global using HTXL_Back_end.Models;
using System.Text;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.IdentityModel.Tokens;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.Filters;

var corsPolicy = "CorsPolicy";

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();

// Authentication
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuerSigningKey = true,
IssuerSigningKey =
new SymmetricSecurityKey(
Encoding.UTF8.GetBytes(builder.Configuration.GetSection("AppSettings:Token").Value!)),
ValidateIssuer = false,
ValidateAudience = false
};
});

// CORS
builder.Services.AddCors(options =>
options.AddPolicy(corsPolicy, policy => policy
.WithOrigins(builder.Configuration.GetSection("AppSettings:AllowedOrigins").Get<string[]>()!)
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials()));

builder.Services.AddDbContext<HTXLPortfolioContext>();

var app = builder.Build();

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

app.UseCors(corsPolicy);

app.UseHttpsRedirection();

app.UseAuthentication();

app.UseAuthorization();

app.MapControllers();

app.Run();
32 replies
CC#
Created by restingphantom on 5/28/2024 in #help
✅ Cors Errors on new API controller
my program.cs looks as followed
32 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
thanks for the help anyways, hopefully nothing breaks again
18 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
I got things to work again, I had to update al packages and sql was doing some funny things but it seams to be fine again
18 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>HTXL_Back_end</RootNamespace>
<UserSecretsId>c33707bf-f6fc-49b5-b0b6-3dbc1bd6d83e</UserSecretsId>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2"/>
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Sdg\Create.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Delete.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Details.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Edit.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Index.cshtml"/>
</ItemGroup>

</Project>
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>HTXL_Back_end</RootNamespace>
<UserSecretsId>c33707bf-f6fc-49b5-b0b6-3dbc1bd6d83e</UserSecretsId>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0"/>
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="8.0.2"/>
</ItemGroup>

<ItemGroup>
<_ContentIncludedByDefault Remove="Views\Sdg\Create.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Delete.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Details.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Edit.cshtml"/>
<_ContentIncludedByDefault Remove="Views\Sdg\Index.cshtml"/>
</ItemGroup>

</Project>
18 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
where can I find that
18 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
nevermind shits way worse
18 replies
CC#
Created by restingphantom on 5/14/2024 in #help
✅ .NET SDK does not support targeted version
I updated my SDK and things seem to be working again, except for my migrations as I now get a authentication error
18 replies
CC#
Created by restingphantom on 5/9/2024 in #help
✅ No route matches the supplied value. when trying put request to /venture/{id}/portfolio
it was the CreatedAtAction I returned in the end of my method
4 replies
CC#
Created by restingphantom on 5/9/2024 in #help
✅ No route matches the supplied value. when trying put request to /venture/{id}/portfolio
omg, I found it
4 replies
CC#
Created by restingphantom on 5/9/2024 in #help
✅ No route matches the supplied value. when trying put request to /venture/{id}/portfolio
Oke, so this works, but as soon as I want to use the id for anything it doesnt see the route
4 replies