Suraj Kumar😎
Suraj Kumar😎
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
/closr
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
Thanks for the help. One last question Umbraco uses razor pages but why not blazor?
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
great!
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "AGN3API", Version = "v1" });

option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Host.UseSerilog((context, configuration) =>
configuration.ReadFrom.Configuration(context.Configuration));

var app = builder.Build();

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

//app.UseHttpsRedirection();
app.UseSerilogIngestion();
app.UseSerilogRequestLogging();
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();

app.Run();
builder.Services.AddSwaggerGen(option =>
{
option.SwaggerDoc("v1", new OpenApiInfo { Title = "AGN3API", Version = "v1" });

option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
In = ParameterLocation.Header,
Description = "Please enter a valid token",
Name = "Authorization",
Type = SecuritySchemeType.Http,
BearerFormat = "JWT",
Scheme = "Bearer"
});
option.AddSecurityRequirement(new OpenApiSecurityRequirement
{
{
new OpenApiSecurityScheme
{
Reference = new OpenApiReference
{
Type=ReferenceType.SecurityScheme,
Id="Bearer"
}
},
new string[]{}
}
});
});
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
builder.Host.UseSerilog((context, configuration) =>
configuration.ReadFrom.Configuration(context.Configuration));

var app = builder.Build();

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

//app.UseHttpsRedirection();
app.UseSerilogIngestion();
app.UseSerilogRequestLogging();
app.UseCors("AllowAll");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();

app.Run();
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
//Adding Authentication
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})

// Adding Jwt Bearer
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudience = builder.Configuration["JWT:ValidAudience"],
ValidIssuer = builder.Configuration["JWT:ValidIssuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Secret"]))
};
});
//Adding Authentication
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})

// Adding Jwt Bearer
.AddJwtBearer(options =>
{
options.SaveToken = true;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters = new TokenValidationParameters()
{
ValidateIssuer = true,
ValidateAudience = true,
ValidAudience = builder.Configuration["JWT:ValidAudience"],
ValidIssuer = builder.Configuration["JWT:ValidIssuer"],
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["JWT:Secret"]))
};
});
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
using Data;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using Serilog;
using System.Configuration;
using System.Text;
using WebApiNeu.MailUtility;
using WebApiNeu.MailUtility.Contracts;
using WebApiNeu.Models;

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();

builder.Services.AddDbContext<TestdusContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

// For Identity
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<TestdusContext>()
.AddDefaultTokenProviders();
builder.Services.Configure<SmtpConfiguration>(builder.Configuration.GetSection("SMTP"));
builder.Services.Configure<MailJetConfiguration>(builder.Configuration.GetSection("MailJet"));
using Data;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using Serilog;
using System.Configuration;
using System.Text;
using WebApiNeu.MailUtility;
using WebApiNeu.MailUtility.Contracts;
using WebApiNeu.Models;

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();

builder.Services.AddDbContext<TestdusContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("DefaultConnection")));

// For Identity
builder.Services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<TestdusContext>()
.AddDefaultTokenProviders();
builder.Services.Configure<SmtpConfiguration>(builder.Configuration.GetSection("SMTP"));
builder.Services.Configure<MailJetConfiguration>(builder.Configuration.GetSection("MailJet"));
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
aye aye
27 replies
CC#
Created by Suraj Kumar😎 on 6/18/2024 in #help
✅ Enable CORS
I did the error still comes... the list is updated now but the error still shows. please help me its very urgent. I am totally stuck
27 replies
CC#
Created by Suraj Kumar😎 on 6/13/2024 in #help
✅ Blazor App
No description
5 replies
CC#
Created by Suraj Kumar😎 on 5/30/2024 in #help
✅ Hangfire as windows service
Thanks for the help guys
21 replies
CC#
Created by Suraj Kumar😎 on 5/30/2024 in #help
✅ Hangfire as windows service
Okay so then I have to create a seprate web app which feeds the table with date and time and then hangfire will scans the table.
21 replies
CC#
Created by Suraj Kumar😎 on 5/30/2024 in #help
✅ Hangfire as windows service
How would I add web interface in the existing service
21 replies
CC#
Created by Suraj Kumar😎 on 5/30/2024 in #help
✅ Hangfire as windows service
A client wants that take the user input and convert it into cron expression and store the data in table so that hangfire scans the table and trigger according to the stored cron expression in the table
21 replies
CC#
Created by Suraj Kumar😎 on 5/27/2024 in #help
✅ In window service app how to get table and column data in asp.net core
Hey @ZZZZZZZZZZZZZZZZZZZZZZZZZ, can you help me please I want to use hangfire as windows service. Is there any example or somthing related to this or can you guide me with this?
13 replies
CC#
Created by Suraj Kumar😎 on 5/27/2024 in #help
✅ In window service app how to get table and column data in asp.net core
var data = await DatabaseService.GetTableDataAsync("WServiceHangfire", "JobName", "Id", "PendingStatus, Date");

var filteredRows = data.Where(row => (bool)row["PendingStatus"]).ToList();

_logger.LogInformation("Fetched {Count} records.",filteredRows.ToArray());
var data = await DatabaseService.GetTableDataAsync("WServiceHangfire", "JobName", "Id", "PendingStatus, Date");

var filteredRows = data.Where(row => (bool)row["PendingStatus"]).ToList();

_logger.LogInformation("Fetched {Count} records.",filteredRows.ToArray());
This only gives the first row
13 replies
CC#
Created by Suraj Kumar😎 on 5/27/2024 in #help
✅ In window service app how to get table and column data in asp.net core
No description
13 replies
CC#
Created by Suraj Kumar😎 on 5/27/2024 in #help
✅ In window service app how to get table and column data in asp.net core
No description
13 replies