Skip to content

Instantly share code, notes, and snippets.

View arcware's full-sized avatar

Dave Donaldson arcware

View GitHub Profile
@arcware
arcware / ServerManager.cs
Last active October 6, 2015 20:52
Create new ServerManager with applicationHost.config
var appHostConfigFile = @"\\{serverName}\c$\windows\system32\inetsrv\config\applicationHost.config";
using (var server = new ServerManager(appHostConfigFile))
{
// Do some stuff
}
@arcware
arcware / ServerManager.cs
Created October 6, 2015 20:46
ServerManager.OpenRemote
using (var server = ServerManager.OpenRemote(serverName))
{
// Do some stuff
}
@arcware
arcware / HttpHeadersExtensions.cs
Last active September 3, 2015 22:02
Serialize HttpHeaders as JSON
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using Newtonsoft.Json;
public static class HttpHeadersExtensions
{
public static string ToJson(this HttpHeaders headers)
{
@arcware
arcware / HttpRequestMessageExtensions.cs
Last active March 2, 2017 05:28
Extension method to extract custom header value from Web API request
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
public static class HttpRequestMessageExtensions
{
public static string GetHeaderValue(this HttpRequestMessage request, string name)
{
IEnumerable<string> values;
var found = request.Headers.TryGetValues(name, out values);
@arcware
arcware / ModifyAppSetting.ps1
Last active June 9, 2021 17:25
Using PowerShell to Modify AppSettings in Web.config
Param($config, $key, $value)
$doc = New-Object System.Xml.XmlDocument
$doc.Load($config)
$node = $doc.SelectSingleNode('configuration/appSettings/add[@key="' + $key + '"]')
$node.Attributes['value'].Value = $value
$doc.Save($config)
@arcware
arcware / gist:cbe8c833b28571db20c4
Created July 7, 2015 18:23
PostSharpHostConfigurationFile in csproj
<PropertyGroup>
<PostSharpHostConfigurationFile>Web.config</PostSharpHostConfigurationFile>
</PropertyGroup>
@arcware
arcware / gist:70debfe2462ac3a0615a
Created July 7, 2015 18:22
Binding redirect for Newtonsoft.Json
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
@arcware
arcware / gist:7c31135fa933483a82e3
Created May 19, 2015 17:10
Using Directives, Correct
using System;
using System.Configuration;
using System.IO;
using NHibernate;
using Twilio;
using MyApp.Common;
using MyApp.Data;
@arcware
arcware / gist:ba78d2a15e4aabea83a6
Created May 19, 2015 17:03
Using Directives, Wrong
using MyApp.Common;
using MyApp.Data;
using NHibernate;
using System;
using System.Configuration;
using System.IO;
using Twilio;
@arcware
arcware / gist:65ec42fc5a24ebda7d56
Last active August 29, 2015 14:18
LowercaseUrls
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.LowercaseUrls = true;
// Other routing stuff here
}
}