12 November 2008

Best Browser For Web Development




Which is the best browser for web development?
The Browser war may be at its highest intense level ever right now with Internet Explorer,
Mozilla Firefox, Opera, Safari haven released their latest versions promising a lot to the
customers and Google haven jumped into the arena with its latest Chrome browser with all new
neat javascript supporting technology.
But all these new web browsers have also put us web developers into a great jepoardy!!! As we have to make sure that our web site runs similarly in all of the above (at least these 3 browsers). Even the testers are having hard time looking at 3 to 5 different windows of the same page at the same time(Good luck to them too!!).

In this all chaos the one browser that i trust and use for my development purpose is Mozilla

Firefox (latest version). Some of its best features are:
1.Tabbed browsing....Now every one seems to have this one
2.Support for Addon Tools and Themes
3.Definately faster browsing speed than IE
4.Huge open source development team!!

Apart from this Firefox is also well responsive to CSS and Javascript. It also has very
powerful web development Adon tools which are worth mentioning here.
1.FireBug-For tracking CSS,Javascript & HTML
2.Web Developer Bar -Provides advanced features including error reporting of Javscript
3.Html Validator -W3C standard HTML validator

One may now think that i am trying to promote Mozilla here, but honestly i have tried IE, Firefox 3 & Chrome, and Firefox surpasses them all with a great margin (provided you install the addons).
Also i would like to mention that Google Chrome seems to be quite promising browser and will definately catch up within a year or so. One unique feature of chrome that i found is that
even if one tab in a window hangs/freezes for some reason you don't have to close the entire
window (I experimented this by putting a javascript into a endless loop)
I havent played with Safari or Opera yet (never needed to!!) but if you readers have
anything worth mentioning about them please feel free to post.
Right now MOZILLA FIREFOX IS THE BEST FOR ME!!

11 November 2008

Javascript function to open a popup

This is a very important and handy javascript to open a popup window, useful in showing small bits of information to user without taking them to different page.

<script> function popup(url) { newwindow=window.open(url,'popup_name','height=500,width=400,left=100,top=100 resizable=yes,scrollbars=yes,toolbar=yes,status=yes'); if(window.focus){newwindow.focus();} } </script>

This function can be called on any event like mouse click by passing the url of the page to be opened in a popup.
Please Note: Firefox does not allow the popup window to be non resizable, hence this feature can not be seen in Mozilla Firefox.

10 November 2008

FCKeditor Common Problem

FCKeditor Problem:
A Potential Dangerous Request Form value was detected from client("")

FCKeditorFCKeditor is great free Web-based HTML text editor to integrate into your website for HTML
editing. Be it ASP.NET or PHP it provides quite a host of features like
fileupload, stylesheets, image uploads etc.
But a very nagging problem that is associated with Fckeditor while using in ASP.NET is the above
titled error.
This error is mostly received when a page containing the Fckeditor server control is loading and
suddenly the user clicks on any other link/button on the page before the current page loads
completely.
Keep in mind that this is a ASP.NET security feature.
A very simple solution to this problem is to set the Page Directives ValidateRequest property to
false. This can be set in the first line of the aspx page as follows..

<%@ Page language="C#" CodeFile="index.aspx" Inherits="Index.aspx.cs" ValidateRequest="false" %>

Note: ValidateRequest is a ASP.NET security mechanism that protects a website from Cross Side Scripting attacks. Disabling this would leave your site vulnerable to such attacks! You can find more about this CSC by googling around.

07 November 2008

Multiple web applications

Disabling web.config Inheritance for Child Applications in Subfolders in ASP.NET 2.0!!
(making multiple web applications work together)


Each ASP.NET Web Application has its own configuration file called web.config file.
In fact every directory in ASP.NET application can have one. Settings in each web.config file apply to the pages in the directory where its placed, and all the subdirectories of that directory.

This is called Configuration Inheritance.

So if you create an ASP.NET application and set its web.config file, add custom HttpHandlers, UrlRewriting module etc and try to create another ASP.NET Web Application in the subfolder, you can end up having problems because application in the subfolder will inherit all the settings from its parent web.config.

So if you for example setup UrlRewriter module in your root web applications like this:

<httpModules>

<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

</httpModules>

And in your child web application (in subfolder) you are not using UrlRewriteModule, then if you try to run the child Web Application in your browser, you will get error like this:
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Could not load file or assembly 'UrlRewritingNet.UrlRewriter' or one of its dependencies. The system cannot find the file specified. (d:\Projects\VS\AspDotNetFaqProject\Website\web.config line 89)

Source Error:

Line 88: <httpModules>
Line 89: <add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter"/>
Line 90: <add name="ScriptModule" type="System.Web.Handlers.ScriptModule,

System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Line 91: </httpModules>


What happens here is that because UrlRewriteModule is configured in the parent's folder web.config file, this setting is inherited by the child application's web.config file, and because of this ASP.NET is looking for the UrlRewriteModule DLL file in the BIN directory, and off course its not there.

Luckily, there is a easy solution to this problem.

First thing you can do is to remove the problematic HttpModule in your child application web.config file using the remove command like this:

<httpModules>

<remove name="UrlRewriteModule" />

</httpModules>

This would remove the handler and your application would run fine.
Or you could use <clear/> command like this:

<httpModules>

<clear/>

</httpModules>

This would clear all the HttpModules in your child application.

But what to do when there are many settings in your root web.config file that you don't want to be propagated to your child applications?

Here is the solution:
With the <location> attribute with inheritInChildApplications set to false in your root web.config file you can restrict configuration inheritance.
So, by wrapping a section of your web.config file in <location> attribute you can instruct ASP.NET not to inherit those settings to child applications/folders and their web.config files.

In fact you can wrap the whole <system.web> section in one <location> attribute and disable configuration inheritance so none of the parent settings from <system.web> will be inherited to the child applications you create in subfolders.

Here is how to use this in practice:

<location path="." inheritInChildApplications="false">

<system.web>
...

</system.web>
</location>

NOTE: Do remember that if you do this, you need to manually insert all the settings you need in the <system.web> for your child applications because none of the settings from the root web.config will be propagated...

01 November 2008

Enforcing SSL Security For WebPages

Many times we need to add SSL security to few of our web pages for secure transactions.
Now initailly when i wanted to do so i tried to hard code the link by using "https://mylink.com ". But if the user typed the link as "http://mylink.com" the page still opened in non secure mode.
To overcome this problem i found a simple function that automatically detects if the page is in secure mode or not and then force it to go into secure mode.

Here is the code for ASP.NET 2.0:

protected void ForceHTTPS()
{
if(!Request.IsSecureConnection)
{
string server_name=HttpUtility.UrlEncode(Request.ServerVariables["SERVER_NAME"]);
string forceurl="https://"+ server_name + Request.FilePath;
Response.Redirect(forceurl);
}
}


and for PHP 5:

function ForceHTTPS()
{
if($_SERVER['HTTPS']!="on")
{
$forceurl="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
header("location:$forceurl");
exit;
}
}

These can be very handy when only a few web pages need SSL.
Note: Please make sure that the server has a valid SSL certificate( need to purchase) for https:// to work other wise you will get page not found error or certificate expired error.