Skip to content

Instantly share code, notes, and snippets.

View shammelburg's full-sized avatar

Sander Hammelburg shammelburg

View GitHub Profile
@shammelburg
shammelburg / azure_appSettings.text
Last active July 29, 2019 14:45
Azure App Services appSettings.*.json configuration
When you want to publish your app and using the Development configuration.
By default this loads Production.
Create an app service
Configure
- AppSettings
- Add
- Name = ASPNETCORE_ENVIRONMENT
- Value = Development
@shammelburg
shammelburg / azure_nodeServices.text
Last active July 29, 2019 14:37
Azure App Services Setup for NodeServices
When you use NodeServices for your project and need to install package make sure you add the following to your app service configuration.
Create an app service
Configure
- AppSettings
- Add
- Name = WEBSITE_NODE_DEFAULT_VERSION
- Value = 10.0.0
- Save
@shammelburg
shammelburg / ZipArchive.cs
Created May 31, 2018 19:16
Create a Zip from ASP.NET Core Web API
[HttpGet]
[Route("/api/download/zip/{Code}")]
public async Task<IActionResult> Zip(string Code)
{
byte[] bytes = null;
using (MemoryStream zipStream = new MemoryStream())
{
using (var zip = new ZipArchive(zipStream, ZipArchiveMode.Create, true))
{
@shammelburg
shammelburg / controller.cs
Created February 19, 2018 11:08
Azure AD | ASP.NET Core | Check if user is in Policy Group
private IAuthorizationService _AuthorizationService;
public HomeController(IAuthorizationService AuthorizationService)
{
this._AuthorizationService = AuthorizationService;
}
[Authorize(Policy = "SecurityGroup")]
public async Task<IActionResult> About()
{
@shammelburg
shammelburg / asppsettings.json
Created February 16, 2018 09:48
Azure AD SecurityGroup Setup
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "Directory.onmicrosoft.com",
"TenantId": "Dictory ID",
"ClientId": "Application ID",
"CallbackPath": "/signin-oidc"
},
//
}
@shammelburg
shammelburg / iformfilecollection.cs
Created October 5, 2017 13:01
IFormFileCollection File Upload AWS
//https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads
[HttpPost]
public void Post(int ItemId)
{
var files = Request.Form.Files;
if (files.Count > 0)
{
using (var client = new AmazonS3Client(_aws.AccessKey, _aws.SecretKey, Amazon.RegionEndpoint.EUWest2))
{
@shammelburg
shammelburg / ssh.txt
Last active September 28, 2017 08:34
ssh commands
// open ssh connection to your remote
ssh user@ip
// ssh tunnel for vnc
// screen share using 'localhost:15900' => 'remote:5900'
ssh -N -p 22 user@ip -L 127.0.0.1:15900:127.0.0.1:5900 -v
// ssh copy mac
// remote location eg. '~/desktop'
scp <local_file_location> user@ip:<remote_location>
@shammelburg
shammelburg / bash.txt
Created September 28, 2017 08:15
Bash Commands
// load bash profile with permission
// write your lines and crtl+o to write - ctrl+x to exit
sudo nano ~/.bash_profile
// if bash profile does not exist
touch ~/.bash_profile
// refresh bash profile after adding alias, etc.
source ~/.bash_profile
@shammelburg
shammelburg / ErrorHandlingMiddleware.cs
Last active September 25, 2017 08:03
ErrorHandlingMiddleware
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate _next;
private readonly EmailSettings _settings;
public ErrorHandlingMiddleware(RequestDelegate next, IOptions<EmailSettings> settings)
{
_next = next;
_settings = settings.Value;
}
@shammelburg
shammelburg / udt.cs
Last active April 5, 2022 18:05
Passing UDT into SP using EF Core
//https://forums.asp.net/t/2071573.aspx?Call+SQL+Server+Function+with+UDT+as+input+parameter
public async Task<int> MainCategorySort(int BrandId, IEnumerable<MainCategoryViewModel> vm, string ModifiedBy)
{
var udt = new DataTable();
udt.Columns.Add("MainCategoryId", typeof(int));
udt.Columns.Add("CMSOrder", typeof(int));
foreach(var item in vm)