To 301 redirect in IIS from http:// to https://,
1. Setup another site and set TCP port to 80 (original site uses other value).
2. Under "Home Directory",
Select "A redirection to a URL",
In Redirect to, type "https://www.example.com$S$Q
3. Check "The exact URL entered above" and "A Permanent redirection for this resource".
Tuesday, January 12, 2010
Generate a CSV from a generic list of objects using reflection and extension methods
http://www.joe-stevens.com/2009/08/03/generate-a-csv-from-a-generic-list-of-objects-using-reflection-and-extension-methods/
using System.Text;
using System.Reflection;
public static class Extensions
{
public static string GetCSV(this List list)
{
StringBuilder sb = new StringBuilder();
//Get the properties for type T for the headers
PropertyInfo[] propInfos = typeof(T).GetProperties();
for (int i = 0; i <= propInfos.Length - 1; i++)
{
sb.Append(propInfos[i].Name);
if (i < propInfos.Length - 1)
{
sb.Append(",");
}
}
sb.AppendLine();
//Loop through the collection, then the properties and add the values
for (int i = 0; i <= list.Count - 1; i++)
{
T item = list[i];
for (int j = 0; j <= propInfos.Length - 1; j++)
{
object o = item.GetType().GetProperty(propInfos[j].Name).GetValue(item, null);
if (o != null)
{
string value = o.ToString();
//Check if the value contans a comma and place it in quotes if so
if (value.Contains(","))
{
value = string.Concat("\"", value, "\"");
}
//Replace any \r or \n special characters from a new line with a space
if (value.Contains("\r"))
{
value = value.Replace("\r", " ");
}
if (value.Contains("\n"))
{
value = value.Replace("\n", " ");
}
sb.Append(value);
}
if (j < propInfos.Length - 1)
{
sb.Append(",");
}
}
sb.AppendLine();
}
return sb.ToString();
}
}
Monday, January 11, 2010
Avoid concurrent login (logout former login session) in ASP.net membership
In login.aspx:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
string sKey = Login1.UserName;
string sValue = Session.SessionID;
Session[sKey] = sValue;
TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(sKey, sValue, null, DateTime.MaxValue, SessTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable, null);
}
In Master Page of admin:
protected void Page_Load(object sender, EventArgs e)
{
string sValue = Cache[HttpContext.Current.User.Identity.Name].ToString();
if (Session.SessionID != sValue)
{
FormsAuthentication.SignOut();
Response.Redirect("login.aspx");
}
}
http://stackoverflow.com/questions/2025908/avoid-concurrent-login-logout-former-login-session-in-asp-net-membership
protected void Login1_LoggedIn(object sender, EventArgs e)
{
string sKey = Login1.UserName;
string sValue = Session.SessionID;
Session[sKey] = sValue;
TimeSpan SessTimeOut = new TimeSpan(0, 0, HttpContext.Current.Session.Timeout, 0, 0);
HttpContext.Current.Cache.Insert(sKey, sValue, null, DateTime.MaxValue, SessTimeOut,
System.Web.Caching.CacheItemPriority.NotRemovable, null);
}
In Master Page of admin:
protected void Page_Load(object sender, EventArgs e)
{
string sValue = Cache[HttpContext.Current.User.Identity.Name].ToString();
if (Session.SessionID != sValue)
{
FormsAuthentication.SignOut();
Response.Redirect("login.aspx");
}
}
http://stackoverflow.com/questions/2025908/avoid-concurrent-login-logout-former-login-session-in-asp-net-membership
Thursday, January 7, 2010
Monday, January 4, 2010
Hash and Encryption
Hash
Hash is 1 way which cannot be decrypted.
Hash method:
1. MD5
2. SHA1
http://dotnetpulse.blogspot.com/2007/12/sha1-hash-calculation-in-c.html
http://www.obviex.com/samples/hash.aspx
http://stackoverflow.com/questions/1454747/how-to-decrypt-md5-or-sha1-is-it-possible
Encryption
Encryption is 2 way and can be decrypted.
Encryption method:
1. TripleDES
2. Rijndael
Rainbow Table
http://en.wikipedia.org/wiki/Rainbow_table
Salt
http://en.wikipedia.org/wiki/Salt_%28cryptography%29
Hash is 1 way which cannot be decrypted.
Hash method:
1. MD5
2. SHA1
http://dotnetpulse.blogspot.com/2007/12/sha1-hash-calculation-in-c.html
http://www.obviex.com/samples/hash.aspx
http://stackoverflow.com/questions/1454747/how-to-decrypt-md5-or-sha1-is-it-possible
Encryption
Encryption is 2 way and can be decrypted.
Encryption method:
1. TripleDES
2. Rijndael
Rainbow Table
http://en.wikipedia.org/wiki/Rainbow_table
Salt
http://en.wikipedia.org/wiki/Salt_%28cryptography%29
Friday, January 1, 2010
Subscribe to:
Posts (Atom)