Posts

Showing posts from September, 2007

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

Book Review: Professional ASP.NET 2.0 Databases

Image
At 500+ pages, Professional ASP.NET 2.0 Databases is the slimmest Wrox "red" book I've read. Unlike most of the other Wrox books, it has a single author - Thiru Thangarathinam. Data Access using ASP.NET 2.0 has been greatly simplified with the introduction of new & enhanced controls and mechanisms. The book covers a wide array of topics related to building data-driven applications with ASP.NET 2.0. It starts with a quick intro of ASP.NET 2.0 & ADO.NET 2.0, dwells in great detail on DataSource Controls (AccessDataSource gets lesser space) & Data bound controls (the emphasis is almost exclusively on GridView) & goes on to cover Transactions, some ADO.NET 2.0 enhancements, Enterprise Library & data acess with SQL Server 2005. There are 2 case studies which although contrived demonstrate how the topics covered in the book can be put to practical use. I found the thorough explanation of implementation of CLR stored procedures useful. I feel the book is rat

Tips on ASP.NET Hosting & Deployment

There is more to putting up a good Web application than just developing it. Capacity planning, finding the right host, tackling deployment issues & maintaining it satisfactorily are the somewhat under-rated aspects that need to be handled carefully. I wanted to compile all the useful articles I find on ASP.NET hosting & deployment for easy reference, so here goes... 1. K. Scott Allen's "10 Tips for Shrink-wrapping ASP.NET Applications" contain sage advice culled from his experience. 2. This is one of the many tips from Scott Gu's ASP.NET 2.0 Tips, Tricks, Recipes and Gotchas series. To prevent accidental deployment of an ASP.NET application in production with the switch enabled within the application’s web.config file, set the retail attribute of deployment element in the machine.config file to true like so: <deployment retail="true"> The retail attribute can only be set at the machine level, not at the application level. 3. The Micr

HOW TO make external links in an existing web page open in a new window with minimal code changes

This tip by Marko can be a big time-saver if you have been ordered to affix the property target="_blank" to half a zillion links in a website (that the last guy who quit forgot to add) so that they open in a new window & vistors to the website are not distracted away. All the hard work is accomplished by a small Javascript function that takes the domain name of the web page as input, scans all links that do not belong to that domain name & programmatically assigns "_blank" value to the target property of their anchor tags. This function is called in the window onload method. A cool spin-off of this by the same author is (what I would like to call) the Link Labeler. It is good to show non-standard web file formats like .PDF, .DOC, .ZIP etc with icons next to it so that when visitors click on the links they are not startled by a File Download dialog box popping up or some other application linked to the file opening up automatically. Like in the previ

Free ASP.NET AJAX E-learning course

A free (possibly for a limited time) 2-hour clinic on Microsoft ASP.NET AJAX is available on Microsoft E-learning . If you are new to ASP.NET AJAX & want to understand the essentials quickly this is a good learning resource. The content is easy to digest & covers an extensive breadth of topics.

HOW TO preserve number formatting while exporting data from a web page to Excel

There are many ways of exporting data from a web page to Excel using ASP.NET . Many of these techniques inherently depend on the ability of Office 2000 (& above) documents to be converted from Word/Excel to HTML (File->Save As) and vice versa. When you have to implement finer details like preserving number formatting etc. in the generated Excel sheet, you may have to utilize the Office XML & CSS code that Office documents themselves natively generate. More info on Office XML & CSS can be found in the Microsoft Office HTML and XML Reference . I have an article on generating Excel sheets dynamically using this Office XML & CSS technique on EggHeadCafe . Using the same technique, I have put up quick & dirty example on preserving number formatting. You can check the demo & source code .