Skip to content

Instantly share code, notes, and snippets.

View sjwaight's full-sized avatar
😎
Happy Days

Simon Waight sjwaight

😎
Happy Days
View GitHub Profile
@sjwaight
sjwaight / web.2.0.config
Created November 17, 2013 02:34
Sample web.config for a basic forms based authentication web application that is using membership and role providers.
<?xml version="1.0"?>
<configuration>
<appSettings />
<connectionStrings>
<!-- you'll need to change this to match your server - the one below is using the default local instance with Windows Auth. -->
<add name="aspnetmembers" connectionString="server=.;initial catalog=AuthDemoApp;Integrated Security=SSPI"/>
</connectionStrings>
<system.web>
<compilation debug="true"/>
<authentication mode="Forms">
@sjwaight
sjwaight / web.4.5.1.config
Created November 17, 2013 08:51
Sample web.config that demonstrates how the previously created web.2.0.config file (https://gist.github.com/sjwaight/7508374) can be updated to support claims-based authentication.
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<appSettings>
<add key="ida:FederationMetadataLocation" value="https://localhost/idsrv/FederationMetadata/2007-06/FederationMetadata.xml" />
<add key="ida:Realm" value="https://localhost/authdemoapp/secured/" />
<add key="ida:AudienceUri" value="https://localhost/authdemoapp/secured/" />
@sjwaight
sjwaight / connectionStrings.config
Created November 17, 2013 09:00
Sample connection strings configuration file from the Thinktecture IdentityServser setup for the associated blog.
<connectionStrings>
<!-- configuration data like endpoints, protocol config, relying parties etc... -->
<add name="IdentityServerConfiguration"
connectionString="server=.;initial catalog=IdentityServerConfiguration;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
<!-- user database -->
<add name="ProviderDB"
connectionString="server=.;initial catalog=AuthDemoApp;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
// utilising RestSharp and Json.NET - get via Nuget.
private WorkItem GetWorkItem(string workItemIdentifier)
{
var restClient = new RestClient("https://account.visualstudio.com/defaultcollection");
restClient.Authenticator = new HttpBasicAuthenticator("username", "password");
// code removed here
var changes = GetWorkItemHistoryComments(restClient, workItemIdentifier);
@sjwaight
sjwaight / ShutdownAllVms.ps1
Last active August 29, 2015 14:05
Example script that shows you how you can retrieve all virtual machines in an Azure subscription and then shut them down.
# Based on the August 2014 PowerShell Cmdlets (v2.4 of Azure SDK)
Import-Module "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Azure.psd1"
Function ForceShutdownVM($virtualMachine)
{
Write-Host "Looking at host" $_.Name -ForegroundColor Yellow
if($_.Status -ne "StoppedDeallocated")
{
if($_.InstanceName -Like "*_IN_*")
{
@sjwaight
sjwaight / 01-Setup-Azure-SQL.ps1
Last active August 29, 2015 14:08
How to deploy two Azure SQL Database Servers in different Regions, provision a new database on one and then setup an active geo-replication relationship between the Servers.
# Helper Method from: https://github.com/guangyang/azure-powershell-samples/blob/master/create-azure-sql.ps1
# You can download this file as part of this repository: https://github.com/sjwaight/uha-azure-sample/
# Create a PSCrendential object from plain text password.
# The PS Credential object will be used to create a database context, which will be used to create database.
Function New-PSCredentialFromPlainText
{
Param(
[String]$UserName,
@sjwaight
sjwaight / 04-Setup-TrafficManager.ps1
Created November 2, 2014 13:38
Example of how to create a new Azure Traffic Manager instance.
# You can download this file as part of this repository: https://github.com/sjwaight/uha-azure-sample/
if($args.Count -eq 0)
{
Write-Host "ERROR: you must supply a unique traffic manager DNS prefix"
Exit 1
}
$tmDomain = "{0}.trafficmanager.net" -f $args[0]
@sjwaight
sjwaight / 02-Setup-CloudServices.ps1
Last active August 29, 2015 14:08
How you can provision an empty Azure Cloud Service ready for your application deployment.
# You can download this file as part of this repository: https://github.com/sjwaight/uha-azure-sample/
Function New-DeploymentRegion
{
Param(
[String]$RegionName
)
####
@sjwaight
sjwaight / 03-Deploy-WebRoles.ps1
Created November 2, 2014 13:41
How we can deploy a rebuilt Azure Package to two separate Cloud Services in different Regions.
# You can download this file as part of this repository: https://github.com/sjwaight/uha-azure-sample/
Function New-AzureCloudServiceDeployment
{
Param(
[String]$RegionName,
[String]$DeploymentPathPackage,
[String]$DeploymentPathConfig
)
public class ContosoCustomDatabaseInitializer : IDatabaseInitializer<SchoolContext>
{
public void InitializeDatabase(SchoolContext context)
{
if (context.Database.Exists())
{
if (!context.Database.CompatibleWithModel(true))
{
context.Database.Delete();
}