Posts

HOW TO manage the ASP.NET ValidateRequest property in different cases

Request Validation is a useful feature in ASP.NET that prevents potentially unsafe input from being submitted to the server with the ValidateRequest property. By default, request validation is enabled in Machine.config. If a user inputs text through an ASP.NET page that has the property ValidateRequest="True", an ugly error page will be thrown. A neat way of handling this error, as shared by Kirk Allen Evans , is to override the OnError Method of the Page class & show a friendly message instead of the regular "A potentially dangerous... " message that could scare a timid user. protected override void OnError(EventArgs e) { System.Exception oops = Server.GetLastError(); if(oops.GetBaseException() is System.Web.HttpRequestValidationException ) { //System.Diagnostics.Debug.Assert(false); //Response.Write(oops.ToString()); //Insert a friendly message asking user not to enter anything like tags. Response.StatusCode = 200; ...

rel="nofollow" - one non-standard HTML attribute value everyone agrees on

If you are keen about high search engine ratings for your web pages, it's important to be in the good books of search engines & know the best and worst sites to get links from . The search algorithms of search engines analyze links to decide how they should be ranked. Comment spamming is one way of spamdexing by which link spammers manipulate the rankings of their website. They do this by injecting their links onto popular websites (which enjoy a good search engine ranking) like blogs through the feedback/comments/guestbook section. Although such mischief cannot be countered without moderation, placing a rel="nofollow" attribute in the anchor tag can defeat the parasitic comment spammers spamdexing intentions. Google, Yahoo, MSN search engines respect this non-standard HTML attribute value & blog engines like Blogger, WordPress & MSN Spaces among others also support it .

HOW TO show UTC Date/Time recorded on the server in the user's regional time zone format.

While I was reading Rick Strahl's commentary of Javascript frameworks & libraries , I remembered how beneficial Matt Kruse's Date library has been to me. The library that comes as a external Javascript file is just 12KB. It has functions to take care of date formatting, parsing, comparing & adding/subtracting dates. I utilized it recently to show UTC Date/Time recorded on the server in the user's regional time zone format using Javascript. In a web application that reaches to a global audience, having timestamps that reflect the server date-time rather than the user's regional date/time & that too in her regular format can make it impersonal & hinder interactivity. If the date/time values are recorded on the server in UTC (Coordinated Universal Time) format, they can be converted into the browser's local format making it more friendlier. I wrote a Javascript function to convert a UTC Date/Time into the visitor's local DateTime format using D...