Skip to content

Instantly share code, notes, and snippets.

View shawnmclean's full-sized avatar
🐭
:)

Shawn Mclean shawnmclean

🐭
:)
View GitHub Profile
@shawnmclean
shawnmclean / IdentityExtensions.cs
Created January 12, 2012 19:58
Custom Identity extention
public static class IdentityExtensions
{
public static CustomIdentity ToCustomIdentity(this IIdentity identity)
{
return (CustomIdentity) identity;
}
}
@shawnmclean
shawnmclean / CustomIdentity.cs
Created January 12, 2012 19:53
Custom user data for asp.net forms authentication
/// <summary>
/// Extra user custom data
/// </summary>
public class UserIdentity
{
public int UserId { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
@shawnmclean
shawnmclean / FormsAuthenticationService.cs
Created January 12, 2012 19:48
FormsAuthentication custom user data
public class FormsAuthenticationService : IFormsAuthenticationService
{
public void SignIn(UserIdentity user, bool createPersistentCookie)
{
//UserData is stored as json
string userData = JsonSerializer.SerializeToString<UserIdentity>(user);
FormsAuthenticationTicket authTicket = new
FormsAuthenticationTicket(1, //version
user.UserId.ToString(), // user name
@shawnmclean
shawnmclean / CountSorted.cs
Created November 13, 2011 23:20
Count Sorted Array
public static int CountSorted<T>(this List<T> list, T item) where T : IComparable
{
//find random index of the item
int index = list.BinarySearch(item);
//if item isn't found, just return -1
if (index < 0)
return -1;
@shawnmclean
shawnmclean / convas2img.htm
Created August 23, 2011 00:43
Convert A canvas to image
<canvas id="MyCanvas" width="300" height="300">
</canvas>
<img id="MyImg"/>
<script>
function drawAndConvertStuff(canvas) {
var canvasContext = canvas.getContext('2d');
//draw a black box
@shawnmclean
shawnmclean / dynamicvalidation.html
Created August 10, 2011 04:11
Unobtrusive jquery validation with dynamic content in ASP.NET MVC
@using (Html.BeginForm())
{
<div id="RegBox" style="display: none;">
@Html.LabelFor(m => Model.Name)
@Html.TextBoxFor(m => Model.Name)
@Html.ValidationMessageFor(m => m.Name)
</div>
<div id="LoginBox">
@Html.LabelFor(m => Model.Email)