Prabir's Blog

where the tech matters...

Fiddler and Visual Studio Web Server - Cassini

October 26
by prabir 26. October 2009 00:41

If you have been tried using Fiddler in localhost of Visual Studio inbuilt Web Server called Cassini, you mite have noticed that you will receive a HTTP 502 error. Saying [Fiddler] Connection to localhost failed.

To solve this you might try adding period (.) after localhost as shown below.

image

For some machines it seems to work but some it doesn’t. In case in yours it doesn’t work try changing localhost to 127.0.0.1 and then adding period (.) after it.

image

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags:

ASP.NET

Custom Error for non ASP.NET files

May 31
by prabir 31. May 2009 13:38

Custom errors are helpful in website to provide information to the users with more friendly errors. I needed to do the same with my blog. But unfortunately only .aspx, .axd and other asp.net files would show the custom error. So navigating to a url (http://blog.prabir.me/badurl.html) that doesn’t exist and is not registered by asp.net would lead me to the following error which was not what I wanted.

image

I needed to extend it in order to support extension less url or other url that are not handled by asp.net.

By default BlogEngine provides me with the following custom error which only works for asp.net files.

<customErrors mode="RemoteOnly" defaultRedirect="~/error404.aspx">
    <error statusCode="404" redirect="~/error404.aspx"/>
</customErrors>

The solution was to modify the web.config, rather add the following piece of code to my <system.webServer> so that it gets handled by IIS (This requires IIS7).

<httpErrors errorMode="Custom" existingResponse="Replace" >
    <remove statusCode="404"/>
    <error statusCode="404" path="/error404.aspx" responseMode="ExecuteURL"/>
</httpErrors>

Now even non asp.net files are handled like shown below.

image

Note: In path=”/error404.aspx”, it start with / not ~/. ASP.NET users should be careful with this otherwise it will not work.

For more information on <httpErrors> refer to the MSDN Library.

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , ,

ASP.NET

HTTP redirection to HTTPS

May 21
by prabir 21. May 2009 22:38

Redirecting and Rewriting a url is one of the most important factor that leads to SEO (Search Engine Optimization). Not just for the computer brains, but also particularly for human brains as it is easier to remember a well formatted url.

It is really difficult for a normal guys out there to remember the whole url, especially if its an HTTPS. Most of the internet users don’t even know what http is.

Lets create a scenario first, in order to know why this is necessary for us. Suppose you got a banking website, which requires the website to use SSL, and require https. Would you put a link in your homepage saying that click here to go to the main banking page and finally lead the customer to your https website? Wouldn’t that be closer to saying goodbye for the customer. Why don’t we automate it?

Now, I’m going to discuss on how to automate the redirection of HTTP to HTTPS. For this tutorial you will require IIS7 and the Rewrite Module to be installed. (Sorry IIS6 guys)

Lets say you want to redirect http://www.mybank.com to https://www.mybank.com

You will require to edit web.config which is on your http site, and add the following line.

<system.webServer>
    <rewrite>
        <rules>
            
            <rule name="Redirect to HTTPS" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTPS}" pattern="^OFF$" />
                </conditions>
                <action type="Redirect" url="https://www.mybank.com" redirectType="SeeOther" />
            </rule>

        </rules>
    </rewrite>
</system.webServer>

That's it, and you are done.

If you want to check out a real example and think why it is important to your website check out http://www.paypal.com.

Web.config file can be downloaded from here:
       iis7_rewrite_http_to_https.zip (397.00 bytes) [Downloads: 146]

If you enjoyed this post, make sure you subscribe to my RSS feed!

Tags: , , ,