Website Optimization: Try to Escape from 404 – Page Not Found
Article ID : Tip-003
Article Topic : Website Optimization
Article Title : Try to Escape from 404 - Page Not Found
Preface
Wen client always creates a request for the resources referenced in the page it is rendering and if server can’t find it sends 404 – Page Not Found.
Explanation
When we create a website with a number of webpages and embedded resources like images (in HTML and CSS), JavaScript Files or Cascading Style Sheets, it is well obvious that we may skip something to include or we have referenced which is not present in the application. If this missing is visible, it can be caught and taken care. But, what if it is not visible?
Let’s talk about the favicon.ico. Microsoft started the concept of the favorite’s icon with IE 4. Since then the trend is started ad is adopted by major browsers to fetch and display the favorite’s icon in the address bar o on the tabs icon (for the bowsers supporting tabs). Earlier the concept was to fetch this icon only when the page is added to the favorite’s menu. But today if the browser has no previous visit recorded for the site the page belongs to will create a domain/favicon.ico request. Once the data is fetched it will cached by the browsers. But if the server returns 404 Error it will try to get that every time the page is requested from the domain.
Most of the cases even after the deployment is over for the site we skip this small thing favicon.ico to be included in the application root and the server is bothered again and again by the requests to provide the information which actually it doesn’t have. Every time without getting frustrated it calmly says 404 – Page Not Found.
How to Resolve
You can avoid this very common situation specifically for the icon case by
- Using a favicon.ico file in the root of the application.
- Specifying the page icon in the header of the page.
There a number of tools available out there in the market (freeware or paid), which can help you find out the web requests and response for your browser. Using them you can identify what is requested and what you have received in response. Fiddler is a free tool used for the same purpose.
Conclusion
Any request which cannot be fulfilled by the server is a burden to the server and to the network and to the client who is making that request. We can actually avoid them by using little cautiousness.
Creating System StoredProcedures in SQL Server
What is System StoredProcedures
A system StoredProcedure is a general stored procedure which started with 'sp_'. System StoredProcedures are stored into the master database in SQL Server.
Requirement of System StoredProcedure
There are instances when you are required to perform some operations on the different databases, like finding the dependency of the table (sp_depends), you use the system StoredProcedure. There are many System StoredProcedure already provided by the SQL Server. some of the most commonly used are:
- sp_who
- sp_depends
- sp_help
- sp_helptext
Each of the above provide some pre-defined functionality, but there are chances where you want your own functionality. In that case you can create your own System StoredProcedures. Just create a StoredProcedure with prefix 'sp_' in the master database and you are ready to go. Here I am showing one I have created for my ease.
Example
-- ======================================
-- Author: Anant Anand Gupta
-- Date: 2010-05-10
-- Description: Return the number of
-- records in the Table
-- ======================================</p>
<p>USE master
GO</p>
<p>IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sp_GetCount]') AND type IN (N'P', N'PC'))
DROP PROCEDURE [dbo].[sp_GetCount]
GO</p>
<p>CREATE PROCEDURE [dbo].[sp_GetCount] @TableName NVARCHAR(776)
AS
BEGIN
SET NOCOUNT ON
DECLARE @str NVARCHAR(1000)
SET @str = 'Select Count(*) [Record Count] From ' + @TableName
EXEC (@str)
END
Now you can execute the stored procedure in any database you want like this:
EXEC sp_GetCount '<TableName>'
Extras
You can also create a keyboard shortcut for the above StoredProcedure to use quickly in between your SQL Code to find out the number of records in the selected table. Go to Tools -> Options -> Keyboard in SQL Server Management Studio. Select the text box in front of the predefined shortcuts which are not used. Enter the name of your StoredProcedure in the TextBox.
Click OK.
Open New Query Window (modifications are not registered with the windows already opened) for the required database. Enter the desired TableName and select the text and press your shortcut (Ctrl + 5 in my case). Here is your result
Enjoy and be more productive at your workplace !!!
Design Patterns
What is a Design Pattern?
If you are here reading this post you might be looking a knowledge on Design Patterns and the first question which comes on anyone's mind is "What is a Design Pattern?". Lets answer this question in your own way.
You are person who know the syntax of a programming language and you are able to successfully convert any requirement into the code. One fine morning you reach office and your senior tells you about a new project requirement. You understood the requirement and have decided whats need to be done and what are the object of classes required to achieve this. But internally, whole the time from beginning to the end of the development you always know that there can be a better way to achieve this, and of course you search for other solutions to. Whatever you decide to implement you will finish off the task, but was that the best solution for the requirement? When this question comes in to you mind, the answer can be only given in terms of Design Patterns.
A design Pattern is nothing but a conceptual way to represent a reusable solution for a typical problem.
Here is a list of all known Design Patterns:
- Strategy Design Pattern
- Decorator Design Pattern
- Factory Design Pattern
- Observer Design Pattern
- Chain of Responsibility Design Pattern
- Singleton Design Pattern
- Flyweight Design Pattern
- Adapter Design Pattern
- Facade Design Pattern
- Template Design Pattern
- Builder Design Pattern
- Iterator Design Pattern
- Composite Design Pattern
- State Design Pattern
- Proxy Design Pattern
- Command Design Pattern
- Mediator Design Pattern
- Abstract Factory Design Pattern
- Prototype Design Pattern
- Bridge Design Pattern
- Interpreter Design Pattern
- Memento Design Pattern
- Visitor Design Pattern
- Circular Design Pattern
- Double Buffer Design Pattern
- Recycle Bin Design Pattern
- Model-View-Controller Design Pattern
- Model-View-View-Model Design Pattern
I will updating the details of each kind of design patterns as soon as they are ready to be posted.
Server.MapPath
In general whenever we need to get physical location of the file in ASP.Net Application, we use Server.MapPath. This is the most commonly adopted method. If you want the file to be located with reference to the path of the current WebPage, then the implementation holds good, but, in case you have to always refer the file from the application root, this method gives you different results. Take the following scenario, where the application directory structure is as follows:
- Root
- Data
- Data.XML
- ClassA.cs (uses Server.MapPath("\Data\Data.XML"))
- ClassB.cs (uses ClassA to get the XML file contents)
- SubDir
- ClassC.cs (uses ClassA to get the XML file contents)
- Data
In the above scenario the ClassC will fail to retrive the contents in case of the WebApplication is hosted in a virtual directory. The application will work fine if it is a website. So the implementation will not show any errors when we run the application from the Visual Studio. to make it more generic we can replace the Server.MapPath with
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"Data\Data.XML".

