IIS 7 URL Rewrite extension and OutputCache conflict

By Mohammad Mahdi Ramezanpour at April 23, 2010 06:30
Filed Under: ASP.NET, IIS

These days, I’m developing a new .NET website which is hosted by Windows Server 2008 R2 and IIS 7.5. For some purposes, I was using the “Intelligencia.UrlRewriter” module which was introduced by Scott Guthrie and everything is working fine on my Windows Server 2003 and IIS 6 home server. I also tested it on my development machine which has a Windows 7 Ultimate installed and everything was going well.

For some security reasons, my hosting company restricted using rewrite modules and they suggested me to use IIS 7 native URL Rewrite extension.

During the migrating process, I realized that the “~” operator is not working correct! Fortunately Ruslan Yakushev was explained about the “~” failure in URL Rewrite module:

You can use the ~ operator in ASP.NET Web server controls to reference the root of the application directory when you need to set a path. However, if URL rewriting changes the directory hierarchy of the requested URL, this can cause links that are specified with the ~ operator to be resolved incorrectly. For example, imagine that the Default.aspx page at the root of a Web application named app1 contains the following Image control:

<asp:Image runat="server" ImageUrl="~/Images/MyImage.gif" />

If URL rewriting changes the URL from http://localhost/app1/folder/file to http://localhost/app1/default.aspx, the links that are specified with the ~ operator will be resolved relative to the rewritten URL path, which would be relative to the /app1 folder. The following example shows the resulting HTML markup for the img element:

<img src="Images/MyImage.gif" ... >

Because the browser requested http://localhost/app1/folder/file, it will try to obtain the image from http://localhost/app1/folder/Images/MyImage.gif. This results in a 404 (File Not Found) error.

The URL Rewrite module for IIS 7.0 includes an update for ASP.NET that fixes this behavior. The update causes the ~ operator in Web server controls to be resolved relative to the originally requested URL. In the previous example, the HTML markup in the response will contain the correct URL path for the img element, as shown in the following markup:

<img src="../Images/MyImage.gif" ... >

The update for ASP.NET applies only to .NET Framework 3.5 SP1 and later. In order to get the update, upgrade the .NET Framework to version 3.5 SP1 and then run the IIS 7.0 URL Rewrite module installer, which will install the ASP.NET update.

But my problem didn’t solve! Even check my web server and saw that it has .NET Framework 3.5 SP1 and UrlRewiter 2.0 installed!!!

After lots of challenges, I realized, the “~” operator in my user controls that has the Output cache directive enabled, doesn’t work well and after I omitted the @OutputCache from my user control, everything was back to normal. Note that if you don’t use the UrlRewrite module in your application, everything will be working well, even if you set the OutputCache directive and I think it’s a bug that should be reported to the Microsoft.

I hope it helps.

Apple iPad in Iran!!!???

By Mohammad Mahdi Ramezanpour at April 06, 2010 08:09
Filed Under: Other

It’s only 3 days that Apple released the iPad and about 1,000,000 people around the world have bought it.

Apple iPad

The iPad is a tablet computer developed by Apple Inc. Announced on January 27, 2010; it is part of a category between a smartphone and a laptop computer.

After 3 days, Iranian local TV reported that a company had imported the iPad to the Iran and they’ve sold about 3,000 iPads to now!!! It’s outstanding. I don’t know about the price yet but I’m going to go to Paytakht in order to get some information about it.

If you live in Iran, you can buy the Apple’s iPad if you want.

UPDATE: According to one of my friends, iPad's price in Iran is about $1200!!! I can't believe that! WTH?

Hope it helps.

How to change Visual Studio 2010 Color Palette

By Mohammad Mahdi Ramezanpour at April 04, 2010 04:51
Filed Under: .NET General

I know a lot of developers who can’t stand Visual Studio color scheme and they need to change the color of it. As you know, Microsoft changed VS’s color scheme to a much better but some of the developers that I know can’t stand it either.

Visual Studio 2010 Color Scheme

After some days of research, I found an extension for Visual Studio 2010 (RC is included) which changes the VS’s color scheme to whatever you want. Here’s an example:

Themed Visual Studio

After you install the extension, a “Theme” menu will be added to your VS IDE:

Theme Menu 

As it’s obvious, you can select from the list of built-in themes or, you can customize a new theme for yourself.

You can download this extension by Click Here.

Matthew Johnson – Developer, Visual Studio Platform, described this extension in details so you can check it out here: http://blogs.msdn.com/visualstudio/archive/2010/01/04/changing-visual-studio-s-color-palette.aspx

Hope it helps.

Currently Reading

Quote of the day

Send Persian SMS