Monday, August 20, 2007

How to force a page to use SSL (HTTPS)

The following sample code will force pages to use SSL (https) with ASP.NET 2.0:




//this is the current url 
System.Uri currentUrl = System.Web.HttpContext.Current.Request.Url;
//don't redirect if this is localhost
if (!currentUrl.IsLoopback)
{
    if (!currentUrl.Scheme.Equals(Uri.UriSchemeHttps, StringComparison.CurrentCultureIgnoreCase))
    {
        //build the secure uri
        System.UriBuilder secureUrlBuilder = new UriBuilder(currentUrl);
        secureUrlBuilder.Scheme = Uri.UriSchemeHttps;
        //use the default port. 
        secureUrlBuilder.Port = -1;
        //redirect and end the response.
        System.Web.HttpContext.Current.Response.Redirect(secureUrlBuilder.Uri.ToString());
    }
}


Hope it helps.
http://www.ikosoftware.com/

Tuesday, August 14, 2007

Use ISO without burning it to a disk.

There is a way to use that ISO without burning it to a disk. And it's free!

Download Microsoft Virtual CD-ROM Control Panel v2.0.1.1 - a free tool from Microsoft to mount ISO images as drives.
http://download.microsoft.com/download/7/b/6/7b6abd84-7841-4978-96f5-bd58df02efa2/winxpvirtualcdcontrolpanel_21.exe

Follow the instruction from the ReadMe.txt file:

Readme for Virtual CD-ROM Control Panel v2.0.1.1
THIS TOOL IS UNSUPPORT BY MICROSOFT PRODUCT SUPPORT SERVICES
System Requirements
===================
- Windows XP Home or Windows XP Professional

Installation instructions
=========================
1. Copy VCdRom.sys to your %systemroot%\system32\drivers folder.
2. Execute VCdControlTool.exe
3. Click "Driver control"
4. If the "Install Driver" button is available, click it. Navigate to the
%systemroot%\system32\drivers folder, select VCdRom.sys, and click Open.
5. Click "Start"
6. Click OK
7. Click "Add Drive" to add a drive to the drive list. Ensure that the
drive added is not a local drive. If it is, continue to click "Add Drive" until
an unused drive letter is available.
8. Select an unused drive letter from the drive list and click
"Mount".
9. Navigate to the image file, select it, and click "OK". UNC naming
conventions should not be used, however mapped network drives should be
OK.
You may now use the drive letter as if it were a local CD-ROM device.
When you are finished you may unmount, stop, and remove the driver from memory using the driver control.

ASP.NET 2.0: CacheKeyDependency

During the development of Issue Tracker ( http://www.ikosoftware.com/ ) , I had a lot of problems with CacheKeyDependency. It simply didn't work. The documentation in MSDN is definitely lacking. I couldn't find any good information on the internet either.

After a lot of trial and error attempts I finally made it work. Let's go through the following code to demonstrate the technique.

Add DataSource objects to the page.
Enable cache for the DataSource object:

.... asp:sqldatasource runat="server" CacheKeyDependency="MyTestKey"....

In code behind check Cache[CacheKeyDependency]. If it does not exists, create it:


 

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //create CacheKeyDependency if it does not exists
            if (Cache[SqlDataSource1.CacheKeyDependency] == null)
            {
                Cache[SqlDataSource1.CacheKeyDependency] = new object();
            }
        }
    }




To refresh the cache use the following code:



 Cache[SqlDataSource1.CacheKeyDependency] = new object(); 
 
 
 


You can have one CacheKeyDependency key word for multiple DataSource objects, so when you run

Cache["MyTestKey"] = new object();  
 
all the DataSource objects will have to renew the cache.


Hope it helps.

Tuesday, August 7, 2007

Creating multiline tooltips (Using Environment.NewLine in tooltips)









Just a small trick to separate lines in the standard tooltip (thanks, Heath!):

Code:
Label1.ToolTip = "Line 1" + Environment.NewLine + "Line 2" + Environment.NewLine + "Line 3";


Hope it helps.
http://www.ikosoftware.com/