Skip to content

Instantly share code, notes, and snippets.

View MahdiKarimipour's full-sized avatar
🎯
Focusing

Mahdi Karimipour MahdiKarimipour

🎯
Focusing
  • TechnologyLeads
  • Sydney, Australia
View GitHub Profile
@MahdiKarimipour
MahdiKarimipour / url-rewrite-through-web-config.xml
Created June 24, 2021 23:45
Url Rewrite Configuration With Web.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\AssemblyName.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
<rewrite>
<rules>
@MahdiKarimipour
MahdiKarimipour / url-rewrite-using-web-config-real-example.xml
Created June 24, 2021 23:47
Url Rewrite Example using Web.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\Home.exe" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
<rewrite>
<rules>
@MahdiKarimipour
MahdiKarimipour / app-settings-sample-file.cs
Created June 25, 2021 00:46
ASP.NET 5.0 Sample App Settings
public class AppSettings
{
public string AllowedOrigins { get; set; }
public string AppName { get; set; }
public SubscriptionApi SubscriptionApiSettings { get; set; }
public JwtTokenConfig AuthSettings { get; set; }
public class JwtTokenConfig
{
public string Issuer { get; set; }
public string Audience { get; set; }
@MahdiKarimipour
MahdiKarimipour / app-settings-injection-into-controller.cs
Created June 25, 2021 00:47
App Settings Injections into Controller
class SampleController
{
public AppSettings settings { get; }
public SampleController(IOptions<AppSettings> options),
{
settings = options.Value;
}
}
{
"AppSettings": {
"AppName": "SampleApp",
"AllowedOrigins": "https://localhost:6500",
"AuthSettings": {
"Issuer": "https://domain.com",
"Audience": "https://domain.com",
"AccessTokenExpiration": 5,
"RefreshTokenExpiration": 60
},
private IConfigurationSection SetupConfiguration(IServiceCollection services)
{
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false)
.AddJsonFile($"appsettings.{environmentName}.json", true)
.AddEnvironmentVariables()
.Build();
var appSettingsSection = configuration.GetSection("AppSettings");
@MahdiKarimipour
MahdiKarimipour / app-settings-usage-in-startup-file.cs
Created June 25, 2021 00:51
App Settings Usage in StartUp File
public void ConfigureServices(IServiceCollection services)
{
IConfigurationSection appSettingsSection = SetupConfiguration(services);
}
@MahdiKarimipour
MahdiKarimipour / app-secrets-sample-class.cs
Created June 25, 2021 00:56
App Secrets Sample Class
public class AppSecrets
{
public JwtTokenConfig AuthSecrets { get; set; }
public SendGrid SendGridSecrets { get; set; }
public Connections ConnectionStrings { get; set; }
public Google GoogleSecrets { get; set; }
public class Google
{
public string CaptchaVerificationSecret { get; set; }
}
public class EmailSender
{
private readonly IConfiguration configuration;
public EmailSender(IConfiguration configuration)
{
this.configuration = configuration;
}
public async Task SendEmailAsync()
{
var sendGridApiKey = configuration
{
"AppSecrets": {
"AuthSecrets": {
"Secret": "jskhdg******vkjdsfhvb"
},
"SendGridSecrets": {
"ApiKey": "kdfhvli******fghvb"
},
"ConnectionStrings": {
"DbConnectionString": "Server = .\MSSQLServer01; Database=****; Trusted_Connection=True; MultipleActiveResultSets=True"