This file contains hidden or 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 static readonly byte[] iv = // array of 16 bytes | |
public static string Encrypt(string message, string password) | |
{ | |
var algorithm = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesCbcPkcs7); | |
var key = algorithm.CreateSymmetricKey(Encoding.UTF8.GetBytes(password).AsBuffer()); | |
var encrypted = CryptographicEngine.Encrypt(key, Encoding.UTF8.GetBytes(message).AsBuffer(), iv.AsBuffer()); | |
return CryptographicBuffer.EncodeToBase64String(encrypted); | |
} |
This file contains hidden or 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
using (var client = new HttpClient()) | |
{ | |
client.DefaultRequestHeaders.Add("Authorization", "Basic d2FsZHlyOjEyMw=="); | |
var strings = await client.GetAsync("/api/values"); | |
var strResult = await strings.Content.ReadAsStringAsync(); | |
var serializer = new JavaScriptSerializer(); | |
var result = serializer.Deserialize<string[]>(strResult); | |
foreach (var s in result) |
This file contains hidden or 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
$.ajax({ | |
url: "http://localhost:36210/api/values", | |
type: "GET", | |
dataType: "json", | |
beforeSend: function(xhr){ | |
xhr.setRequestHeader('Authorization', 'Basic d2FsZHlyOjEyMw=='); | |
}, | |
success: function(data) { | |
$(data).each(function(index, value){ | |
console.log(index + ') '+ value); |
This file contains hidden or 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 AppBasicAuthenticationAttribute : BasicAuthenticationAttribute | |
{ | |
public override string Realm { get { return "DOMINIO"; }} | |
public override bool Authorize(string username, string password) | |
{ | |
var membershipService = IoC.Current.Resolve<IMembershipService>(); | |
return membershipService.ValidateUser(username, password); | |
} | |
} |
This file contains hidden or 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
if (Regex.IsMatch(Request.Url.AbsoluteUri, @"^((http|https)://[^www]).*$")) | |
{ | |
string newDomain = String.Format("{0}://www.{1}{2}", | |
Request.Url.Scheme, | |
Request.Url.Authority, | |
Request.Url.AbsolutePath); | |
Response.Status = "301 Moved Permanently"; | |
Response.AddHeader("Location", newDomain); | |
Response.End(); |
This file contains hidden or 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
using System; | |
using System.Net; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Text; | |
using System.Threading.Tasks; | |
using WebApiContrib.Internal; | |
namespace WebApiContrib.MessageHandlers | |
{ |
OlderNewer