Tuesday, August 25, 2009

Converting string for Safe Rewrite URL

public class SafeURL
{
///
/// A regex that matches all characters that would return false when passed to
///

private static readonly Regex SpecialChars = new Regex(@"[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nd}]");

private static readonly Regex EmbeddedEncodedValue = new Regex(@"-[0-9A-F]{1,8}-");

///
/// URL Encode and Replace URL characters
///

/// Original URL
/// URL
public static string UrlEncode(string url)
{
if(url == null) return null;

// replace special chars.
string result = SpecialChars.Replace
(url, match =>
{
StringBuilder buf = new StringBuilder();
buf.Append("-");
// we must convert to UTF8 first to make sure we're representing the bytes
// appropriately.
foreach (byte c in Encoding.UTF8.GetBytes(match.Value))
{
buf.Append(c.ToString("X2"));
}
buf.Append("-");
return buf.ToString();
});
// and now we're ok to use proper URL encoding
result = HttpUtility.UrlEncode(result);

return result;
}

///
/// Replace and Decode URL charaters
///

/// URL
/// Original URL
public static string UrlDecode(string url)
{
if (url == null) return null;

// decode url encoding
string result = HttpUtility.UrlDecode(url);

// replace special chars.
result = EmbeddedEncodedValue.Replace
(result, match =>
{
string utf8 = match.Value.Trim('-');
int count = utf8.Length / 2;
byte[] bytes = new byte[count];
for(int i = 0; i < count; i++)
{
bytes[i] = Byte.Parse(utf8.Substring(i * 2, 2), NumberStyles.HexNumber);
}
return Encoding.UTF8.GetString(bytes);
});

return result;
}
}

Friday, October 10, 2008

Easy File Download from web

Its a single line code to download a file given a url and downlaod dir

(new WebClient()).DownloadFile(url, downlaoddir);

But if there is windows authentication required on the site the maybe three lines :)

WebClient client = new WebClient();
client.UseDefaultCredentials = true;
client.DownloadFile(url, downloaddir);

But it seems to a very easy option to work with.
It also provides multiple async downloads etc.

Ex:

WebClient wc = new WebClient();
string website1 = "http://remote1.ispnet.net";
string website2 = "http://remote2.ispnet.net";
string website3 = "http://remote3.ispnet.net/login";


NetworkCredential nc1 = new NetworkCredential("mike", "guitars");
NetworkCredential nc2 = new NetworkCredential("evonne", "singing", "home");
NetworkCredential nc3 = new NetworkCredential("alex", "drums");

CredentialCache cc = new CredentialCache();
cc.Add(new Uri(website1), "Basic", nc1);
cc.Add(new Uri(website2), "Basic", nc2);
cc.Add(new Uri(website3), "Digest", nc3);

wc.Credentials = cc;

wc.DownloadFile(website1, "website1.htm");
wc.DownloadFile(website2, "website2.htm");
wc.DownloadFile(website3, "website3.htm");

form - Example Reference

Read/Modify Application Configuration .config file

Read
string value = ConfigurationManager.AppSettings["oldPlace"];

Write

System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");

Thursday, September 11, 2008

Add On - Integrating Browser & Outlook

Browser add on to provide capabilities to use outlook stored information like contacts, emails etc without leaving the browser.

get contact mail address
attach mails from outlook to email in browser

Thursday, August 21, 2008

Enable Maintainanace plan for SQL Server 2005

run the script:

use msdb
GO
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
GO
RECONFIGURE
GO

go to maintainance plan to see details about how to create them

Wednesday, August 13, 2008

SMMS - Short Message Mailing System

SMMS i.e. Short Message Mailing System

A system which provides the feature of a mailing system like (address, lists, reply, forward etc) based on SMS.

Additionally it can have a feature where a person can expose a contact list to someone he know, without the other person being aware of who all are the contact list(acting as a middle man).

This can be a faster, reliable and social way to make people aware of  things going on.

 

Monday, August 11, 2008

Windows vista security - rendered useless by researchers

LAS VEGAS -- Two security researchers have developed a new technique that essentially bypasses all of the memory protection safeguards in the Windows Vista operating system, an advance that many in the security community say will have far-reaching implications not only for Microsoft, but also on how the entire technology industry thinks about attacks.

In a presentation at the Black Hat briefings, Mark Dowd of IBM Internet Security Systems (ISS) and Alexander Sotirov of VMware Inc. discussed the new methods they've found to get around Vista Protections such as Address Space Layout Randomization (ASLR), Data Execution Prevention (DEP) and others by using Java, ActiveX controls and .NET objects to load arbitrary content into Web browsers.

By taking advantage of the way that browsers, specifically Internet Explorer, handle active scripting and .NET objects, the pair have been able to load essentially whatever content they want into a location of their choice on a user's machine.

http://searchsecurity.techtarget.com/news/article/0,289142,sid14_gci1324395,00.html