This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HttpHeaderAttribute : ActionFilterAttribute | |
{ | |
/// <summary> | |
/// The name of the Http Header | |
/// </summary> | |
public string Name { get; set; } | |
/// <summary> | |
/// The value of the Http Header | |
/// </summary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private bool ValidatePassword(User user, string password) | |
{ | |
//hash the password with the saved salt for that user | |
string hashed = cryptoService.Compute(password, user.PasswordSalt); | |
//return true if both hashes are the same | |
return hashed == user.Password; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private const int SALT_SIZE = 16; | |
private const int HASH_ITERATIONS = 50; | |
private void SetNewPassword(User user, string newPassword) | |
{ | |
//a new password hash is generated from a generated salt with the passed settings | |
user.Password = user.Password = cryptoService.Compute(newPassword, SALT_SIZE, HASH_ITERATIONS); | |
//assigning the generated salt to the user | |
user.PasswordSalt = cryptoService.Salt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private ICryptoService cryptoService = new PBKDF2(); | |
private void SetNewPassword(User user, string newPassword) | |
{ | |
//a new password hash is generated from a generated salt with the default settings | |
user.Password = cryptoService.Compute(newPassword); | |
//assigning the generated salt to the user | |
user.PasswordSalt = cryptoService.Salt; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public HttpResponseMessage GetText() | |
{ | |
try | |
{ | |
string content = "Hello"; | |
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); | |
result.Content = new StringContent(content); | |
//a text file is actually an octet-stream (pdf, etc) | |
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Your ValuesController.cs | |
//Version 1 | |
string uri = Url.Route("Default", new { controller="Home", action="MyAction", id = 1 }); | |
string absoluteUrl = new Uri(Request.RequestUri, uri).AbsoluteUri; | |
//http://localhost/Home/MyAction/1 | |
//Version 2 | |
string uri = Url.Route("DefaultApi", new { id = 1 }); | |
string absoluteUrl = new Uri(Request.RequestUri, uri).AbsoluteUri; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var awayCallback = function(){ | |
console.log(new Date().toTimeString() + ": away"); | |
}; | |
var awayBackCallback = function(){ | |
console.log(new Date().toTimeString() + ": back"); | |
}; | |
var activity = new Activity({ | |
onAway: awayCallback, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myObj = this; | |
someMethod = function(){ | |
myObj.myProp; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Canvas to image</h2> | |
<canvas id="MyCanvas" width="300" height="300"> | |
</canvas> | |
<img id="MyImg"/> | |
<script> | |
function drawAndConvertStuff(canvas) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Welcome back @(User.Identity.ToCustomIdentity().FirstName) @(User.Identity.ToCustomIdentity().LastName) |