Skip to content

Instantly share code, notes, and snippets.

View hd9's full-sized avatar

Bruno Hildenbrand hd9

View GitHub Profile
@hd9
hd9 / Blog-VerifyAllowAnonymousAttribute-Usage.cs
Last active February 7, 2020 19:24
How to validate incoming requests on ASP.NET endpoints using custom ActionFilters
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2017/12/aspnet-allowing-anonymous-requests-on.html
// **********************************************
[HttpPost]
[ValidateAntiForgeryToken]
[RequirePermission("Update")]
public async Task<JsonResult> SomeOperation(string id)
{
// your code here
@hd9
hd9 / NServiceBus-WebJob.cs
Last active February 7, 2020 19:25
Sample initialization code for NServiceBus running on Azure WebJobs
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/migrating-nservicebus-backends-to-azure.html
// **********************************************
// Related docs:
// * NSB WebJobs: https://docs.particular.net/samples/azure/webjob-host/
// * Azure WebJobs: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started
public class Program
{
@hd9
hd9 / NServiceBus-WebJob-Debug.cs
Last active February 7, 2020 19:26
Sample initialization code for NServiceBus running on Azure WebJobs supporting local debug
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/migrating-nservicebus-backends-to-azure.html
// **********************************************
// Related docs:
// * NSB WebJobs: https://docs.particular.net/samples/azure/webjob-host/
// * Azure WebJobs: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started
public class Program
{
@hd9
hd9 / MyApp.nuspec
Created February 7, 2020 20:18
Sample NuGet for deploying NServiceBus on Azure WebJobs
<!--
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/migrating-nservicebus-backends-to-azure.html
// **********************************************
-->
<?xml version="1.0"?>
<package>
<metadata>
@hd9
hd9 / MassTransit-SimpleService.cs
Created February 7, 2020 20:27
MassTransit - Console Hosted Service initialization
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2018/08/masstransit-real-alternative-to.html
// **********************************************
using System.Threading;
using System.Threading.Tasks;
using MassTransit;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@hd9
hd9 / MassTransit-SimpleService-Client.cs
Created February 10, 2020 21:58
MassTransit - Example os simple client service
// **********************************************
// Fore more information, visit:
// Blog: https://blog.hildenco.com/2018/08/masstransit-real-alternative-to.html
// Source: https://github.com/MassTransit/Sample-Direct
// **********************************************
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Contracts;
using MassTransit;
@hd9
hd9 / MassTransit-SimpleService-Server.cs
Last active February 10, 2020 22:08
MassTransit - Example os simple server
// **********************************************
// Fore more information, visit:
// Blog: https://blog.hildenco.com/2018/08/masstransit-real-alternative-to.html
// Source: https://github.com/MassTransit/Sample-Direct
// **********************************************
using System;
using System.Threading.Tasks;
using Contracts;
using MassTransit;
@hd9
hd9 / NServiceBus-WebJob-async.cs
Last active February 10, 2020 22:11
Sample debug/async initialization code for NServiceBus running as Azure WebJobs
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/02/migrating-nservicebus-backends-to-azure.html
// **********************************************
// Related docs:
// - NSB WebJobs: https://docs.particular.net/samples/azure/webjob-host/
// - Azure WebJobs: https://docs.microsoft.com/en-us/azure/app-service/webjobs-sdk-get-started
public class Program
{
@hd9
hd9 / aspnet-ai-telemetry-trackException.cs
Last active February 18, 2020 22:02
Handling exceptions on ASP.NET Core web posting to Application Insights
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html
// **********************************************
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
// IExceptionHandlerPathFeature requires Microsoft.AspNetCore.Diagnostics
// run: dotnet add package Microsoft.AspNetCore.Diagnostics --version 2.2.0
var error = HttpContext.Features.Get<IExceptionHandlerFeature>();
@hd9
hd9 / aspnet-ai-telemetry-trackEvent.cs
Last active February 18, 2020 22:02
Posting a custom event from an ASP.NET Core web application to Application Insights
// **********************************************
// Fore more information, visit:
// https://blog.hildenco.com/2020/03/adding-application-insights-telemetry.html
// **********************************************
public IActionResult Privacy()
{
_telemetry.TrackEvent($"Privacy requested @ {DateTime.UtcNow} UTC");
return View();
}