Skip to content

Instantly share code, notes, and snippets.

View RhysC's full-sized avatar

Rhys Campbell RhysC

  • Perth; Australia
View GitHub Profile
@RhysC
RhysC / gist:11362100
Created April 28, 2014 04:54
asafaweb Excessive headers fixes
//On start up :
MvcHandler.DisableMvcResponseHeader = true;
// as an http module/global asax
protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
// Remove the "Server" HTTP Header from response - security review recommends against sending this
var app = sender as HttpApplication;
if (app == null || null == app.Context) return;
@RhysC
RhysC / UnhandledException.cs
Created May 12, 2014 06:35
Events that you should be using to get UnhandledExceptions
// .NET/CLR app domains
// You - always want to be logging these errors!
AppDomain.CurrentDomain.UnhandledException += (s,e) => {};
// Framework specific handlers
System.Windows.Application.Current.DispatcherUnhandledException += (s,e) => {}; // WPF
System.Windows.Forms.Application.ThreadException += (s,e) => {}; // Windows Forms
System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (s,e) => {}; // TPL - not really very imporant
// ASP.NET (i'm guessing you hook into this in your Global.asx?)
@RhysC
RhysC / ExpectedObjectJasmineMatcher.js
Last active August 29, 2015 14:03
Expected Object like approach in Jasmine - Tags - JavaScript JS TDD Spec ExpectedObject Matcher addMatchers 2.0
var customMatchers = {
toInclude: function (util, customEqualityTesters) {
return {
compare: function (actual, expected) {
if (expected === undefined) {
expected = '';
}
var result = {
message: '',
@RhysC
RhysC / CmsController.cs
Last active August 29, 2015 14:04
Looking at a prisimic backed semi structure content delivery system...(TM) ;)
public class CmsController : BootstrapBaseController
{
private readonly PrismicProxy _prismicProxy;
public CmsController(PrismicProxy prismicProxy)
{
_prismicProxy = prismicProxy;
}
public ActionResult Dynamic(string id)
@RhysC
RhysC / CacheTests.cs
Last active August 29, 2015 14:05
Cache of T
using System;
using System.Threading;
using Xunit;
namespace MyNameSpace.Tests
{
public class CacheTests
{
[Fact]
public void CanReuseCachedObject()
@RhysC
RhysC / OwinSample.cs
Created September 12, 2014 06:02
OWIN sample midlewares in a console app
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using OwinSpike.Simple.Console;
//Console app
//NuGet packages :
//<package id="Microsoft.Owin.SelfHost" version="3.0.0" targetFramework="net45" />
@RhysC
RhysC / ClientStartUp.cs
Created September 24, 2014 10:09
Claims not coming back from identity server
using System.Collections.Generic;
using System.IdentityModel.Tokens;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.OpenIdConnect;
using OauthScratch.MvcOwinClient;
using Owin;
@RhysC
RhysC / Log4NetAppenderFactory.cs
Created October 14, 2014 07:50
RestTest - sample console app for receiving HTTP Posts and logging said posts. Posting to http://localhost.fiddler:9000/api/test will allow you to see the request in fiddler
using System.IO;
using log4net.Appender;
using log4net.Core;
using log4net.Layout;
namespace RestTest.Logging
{
public static class Log4NetAppenderFactory
{
private static readonly PatternLayout PatternLayout = new PatternLayout("[%-5level][%date][%thread][%logger]: %message%newline");
@RhysC
RhysC / LinqpadAsAWebserver.linq
Created October 17, 2014 04:17
Linqpad continues to be the coolest thing ever - WEBAPI in Linqpad with out all the drama. Logs all posts
<Query Kind="Program">
<Reference>&lt;RuntimeDirectory&gt;\System.Net.Http.dll</Reference>
<NuGetReference>Microsoft.AspNet.WebApi.OwinSelfHost</NuGetReference>
<Namespace>Microsoft.Owin.Hosting</Namespace>
<Namespace>Owin</Namespace>
<Namespace>System.Web.Http</Namespace>
<Namespace>System.Net.Http</Namespace>
<Namespace>System.Net</Namespace>
</Query>
@RhysC
RhysC / ObjectNotFoundExceptionFilterAttribute.cs
Created November 11, 2014 07:15
Error Handling 404 in Asp.Net MVC 5
using System.Web.Mvc;
namespace YourWebsite.Filters
{
public class ObjectNotFoundExceptionFilterAttribute : ActionFilterAttribute, IExceptionFilter
{
public void OnException(ExceptionContext filterContext)
{
if (filterContext.Exception is NHibernate.ObjectNotFoundException)
{