Adnan’s Blog

Asp.net Read Reciept Request

Posted by: adnanrashid on: September 28, 2008

Heres a quick tip. If you need to include a request for read receipt like Microsoft Outlook while sending mails through Asp.net, just add the Disposition-Notification-To Header to the MailMessage.

The MailMessage class does not have a corresponding attribute and thus it has to be set through the Header.

MailMessage mm = new MailMessage(fromAddress, toAddress);
mm.Subject = subject;
mm.Headers.Add("Disposition-Notification-To", sendReadReceiptToAddress);

Please keep in mind that this is only a request, and can be rejected/ignored by the Mail Client/User configuration.

Generic Handler – Session State

Posted by: adnanrashid on: September 26, 2008

In my current project I needed to access the Session state in a Generic Handler. To my dismay, i realized that the Session StateBag was null. The StateBag class is sealed and manages the Viewstate of the Asp.net server controls and pages.

Upon discussion with my colleague, Mr. Hamed, we found the solution to my problem. Using the IRequiresSessionState interface in System.Web.SessionState, we got access to Session state.

According to Microsoft “Specifies that the target HTTP handler requires read and write access to session-state values. This is a marker interface and has no methods.

Another option was to use the IReadOnlySessionState interface (Specifies that the target HTTP handler requires only read access to session-state values. This is a marker interface and has no methods.)

Needless to say, there is a performance increase in the latter case and if your requirement is only to read Session state, then that would be the right choice

Remove project from Recent Projects in Visual Studio

Posted by: adnanrashid on: September 15, 2008

Recently, I felt the need for removing a project from the Visual Studio Start Page, so I Googled and would like to share the solution. Don’t forget to close visual studio before trying this out. This trick requires modification to registry, so if you are skeptical do make a backup of the registry before proceeding.

Start the registry :

Start > Run > regedit > HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\ProjectMRUList

Then delete the key that has the project you want to remove.

Visual Studio > 9.0 > ProjectMRUList

Visual Studio > 9.0 > ProjectMRUList

Note:

  • The Project Keys are consecutive. So if you have 5 projects listed, and you delete the key for the 4th project ie File4, the 5th project (File5) will also not be shown. You will need to remain one of the keys so that the list remains consecutive.
  • The same procedure can be repeated for the FileList and Find sections of the registry

Google Chrome

Posted by: adnanrashid on: September 14, 2008

Being a Web Developer, I don’t know whether to rejoice the addition of another browser or not? With all the hype of IE 8 ; Cross-Browser compatibility and now this, life sure is chaotic.

I am not going to blog about the new features of Google Chrome (We already have tons of them). It’s been analyzed that Chrome has been optimized for Google Applications and Services. Is that a bad thing??? Frankly, i don’t think so, cos admit it or not, every netizen is dependent on them. But i do welcome the Process-Thread architecture in Chrome, cos i had the same problem in both IE and Firefox.

We can all expect great things from Google, lets hope its the same with Chrome. Good luck to the development and Congrats on the Beta release.

7 really awesome things about Google Chrome : http://mashable.com/2008/09/03/awesome-google-chrome/

Google Chrome Introduction (Comic Book) : http://www.google.com/googlebooks/chrome/index.html

Tags:

SQL Injection Scanner

Posted by: adnanrashid on: August 13, 2008

Being a web developer, its important we realize the threat and severity of SQL Injection. Unfortunately detecting such vulnerabilities is time-consuming and eventually we might not even be able to identify all the loop holes.

HP Security Labs provides a free tool called Scrawlr that scan your site and patches up the exploits. This great tool has proved to be quite helpful and comes highly recommended.

http://tinyurl.com/sql-injection

Tags:

CSS Compressor

Posted by: adnanrashid on: July 16, 2008

As a web designer, we use resources like CSS and javascript. These files should be optimized using compression for reducing the file size and hence the load time.

To decrease the file size web designers can follow 3 guidelines:

  1. Remove whitespace like tabs, spaces, blank lines, etc.
  2. Remove unused CSS classes and ID’s.
  3. Use shorthand wherever applicable. For example use #FFF instead of #FFFFFF or 0 for 0px.

There are various online tools available for CSS Compression. One of them is Clean CSS. This nifty tool, allows you to enter the css code or point it to an online css file and provides many other options along with feature to select the level of compression.

You can try it out on :

http://www.cleancss.com/

Tags:

Encypting query string in asp.net

Posted by: adnanrashid on: July 8, 2008

When you pass information from one page to another, you are passing information that anybody can sniff. For example consider a scenario, in which you pass the customer id as a query string:

http://www.yourapplication.com?customer_id=15

Now if somebody replaced 15 with say 10 or any other number, they can pull up other customer information. And thats a bad for security.

One solution to this problem is to use ecryption using a secret key. So lets use a hard-to-crack 8 byte key like $zm0!qp?

To accomplish this heres a code snippet


using System;
using System.IO;
using System.Xml;
using System.Text;
using System.Security.Cryptography;

public class Encryption64
{
private byte[] key = {};
private byte[] IV = {18, 52, 86, 120, 144, 171, 205, 239};

public string Decrypt(string stringToDecrypt, string sEncryptionKey)
{
byte[] inputByteArray = new byte[stringToDecrypt.Length + 1];
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey, 8);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(stringToDecrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}

public string Encrypt(string stringToEncrypt, string sEncryptionKey)
{
try {
key = System.Text.Encoding.UTF8.GetBytes(sEncryptionKey, 8);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(stringToEncrypt);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (Exception e) {
return e.Message;
}
}
}

The end user will get to see a random text in the query string, something like

http://www.yourapplication.com/Receive.aspx?key=a2f5ckj?h79#8dd3

Remember stay secure stay safe.

Compare Fonts

Posted by: adnanrashid on: July 8, 2008

I was designing a template for a web application and i wanted to try out something new. The user interface revolves around a compatible set of layout, colors, images and fonts. So i was Googling for a tool to help me compare Fonts and thier web compatibility. I came across a great tool called Typetester. Typetester allows you to customize and compare upto 3 fonts side by side in all variants including bold, italic, uppercase, etc simultaneously.

If you want to try it out yourself, visit http://typetester.maratz.com/

Tags:

Picnik Online Image Editing

Posted by: adnanrashid on: July 7, 2008

Although we cant all be photo image editing experts, tools like this can definitely help you come very close. Picknik provides a clean and easy user interface that will get you started on tweaking your favorite images in no time. With an abundant set of Fonts, special effects and other advanced settings, this tool is a must use. The service is offered in both free and premium flavors. It also provides a decent API for developers to integrate certain features in their own applications also with some good tutorials.

Picnik Online Image Editing

http://www.picknik.com

You can also check out a Firefox plugin on https://addons.mozilla.org/en-US/firefox/addon/4889

Tags:

Prestashop-Open Source e-Commerce Solution

Posted by: adnanrashid on: July 7, 2008

Prestashop is a welcome addition to the list Open source e-commerce solutions. The solution is completely configured with two sections, the front end; which deals with the online store’s user interface and the back end; which provides various tools to configure products, categories and other usual product related stuff. What sets Prestashop apart is its robustness and ease of use, making it very simple to install and configure. The upcoming versions plan on supporting Google Checkout, downloadable pdf catalogs and much more. Check it out…

Open Source e-Commerce Solution

Open Source e-Commerce Solution