"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Saturday, September 24, 2011

Response.RedirectPermanent in asp.net

It is continuous process to either move web pages or content in Web Application development over the years. Search Engine Optimization and page hit count, getting more traffic for the website is the most important things in day today, moving pages or ceasing pages might not find the new page hits in search engines.

For example: Imagine that you have categories of products in your E-Commerce web application. When the old categories are replaced or updated by new categories, each year a page in your site might be replaced or updated accordingly. If any external sites (or even internal pages) have links to the category of these web pages in your web application, when link is clicked for the next time then it would have thrown error.

You would typically use Reponse.Redirect to suppress the error. But this is a manipulation, not actual work. This will work for the visitor but it internally 302 redirect.

Response.Redirect
In previous versions of ASP.NET we are using Response.Redirect that redirects to HTTP 302 found status response in turn redirects the page URL temporarily to the specified page URL. This is extra overhead to the server, performance hit here.

Problems
1. There is a round trip here.
2. 302 redirect is temporary redirect for the page.
3. No Search Engine Optimization (SEO) benefits due to this approach
4. You are neither informing search engine to updated internal indexes nor pass old page rank to new page.

Solution: Issuing permanent HTTP 301 redirect will solve the purpose, directly available in ASP.NET 4.0

Importance of HTTP Response Code 301:
This happens to move some WebPages or entire website from one domain to another or change the URL of some of the pages inside the website most of the time. This is quite difficult for a webmaster who deletes the pages from the old server, maps them to the new domain. In this case webmaster looses SEO that is related to previous links. In order to prevent SEO loss we need to make use of 301 Redirects.
HTTP Response Code 301 instructs the browser that the particular page has been moved permanently from the old location to the new location. The benefit of using 301 Redirects is that the search engine, crawlers store SEO information related to the old link based on 301 redirects. It also informs the search engines that the page location has permanently moved and it needs to index the page from the new location in future. This is really useful for search engines like Bing or Google that will carry over page rank to the new page if this status code is seen.

Response.RedirectPermanent
It’s the method of Page.HTTPReposne class that permanently redirects a requested URL to specified URL and issue HTTP 301response code Moved permanently responses. It uses the URL given by the location header. Unnecessary round trip for the browser is eliminated using this feature. This is used in migrating websites from old domain to new domain especially. As inbound traffic is important for significant usage of the web application this option is very much useful in live web applications as the requested URL is permanently redirected to some location using this mechanism. Since the redirection is HTTP 301 response status, search engine knows the new link that is redirected and results in the redirect.
Syntax :

Response.RedirectPermanent("/newlocation/oldcontent.aspx");

 Stay Tune...
 Have a nice day... 'N happy Coding :)

Wednesday, September 21, 2011

NULLIF function in sql

The NULLIF function takes two arguments. If the two arguments are equal, then NULL is returned. Otherwise, the first argument is returned. 
Table Sales_Data
Store_name
Actual
Goal
Store A
50
50
Store B
40
50
Store C
25
30
We want to show NULL if actual sales is equal to sales goal, and show actual sales if the two are different. To do this, we issue the following SQL statement:
SELECT Store_name, NULLIF(Actual,Goal) FROM Sales_Data;
The result is:
Store_name
NULLIF(Actual,Goal)
Store A
NULL
Store B
40
Store C
25

Stay Tune.
Have a nice day... 'N happy Coding :)

Tuesday, September 20, 2011

Coalesce Function in sql

The COALESCE function in SQL returns the first non-NULL expression among its arguments.
 
Table Contact_Info
Name
Business_Phone
Cell_Phone
Home_Phone
Jeff
531-2531
622-7813
565-9901
Laura
NULL
772-5588
312-4088
Peter
NULL
NULL
594-7477

and we want to find out the best way to contact each person according to the following rules:
1. If a person has a business phone, use the business phone number.
2. If a person does not have a business phone and has a cell phone, use the cell phone number.
3. If a person does not have a business phone, does not have a cell phone, and has a home phone, use the home phone number.
We can use the COALESCE function to achieve our goal:
SELECT Name, COALESCE(Business_Phone, Cell_Phone, Home_Phone) Contact_Phone
FROM Contact_Info;
Result:
Name
Contact_Phone
Jeff
531-2531
Laura
772-5588
Peter
594-7477



Have a nice day... 'N happy Coding :)

Monday, September 19, 2011

Retrieve custom message if column is null in query

Hi *.*,
 Retrieve custom message if column value is null using query. Oracle, Mysql MSSQL all are providing different keyword for this purpose

NVL() function For Oracle
This function is used to replace NULL value with another value.
Table Sales_Data
store_name
Sales
Store A
300
Store B
NULL
Store C
150







  • SELECT  NVL(Sales,’No data Avilable’) FROM Sales_Data
  • SELECT SUM(NVL(Sales,100)) FROM Sales_Data;
2nd query will returns 550. This is because NULL has been replaced by 100 via the ISNULL function, hence the sum of the 3 rows is 300 + 100 + 150 = 550. 

 ISNULL() function for SQL Server
is used to replace NULL value with another value.

SELECT ISNULL(Sales,’No data avilable’)) FROM Sales_Data;
 IFNULL Function for MySQL
This function takes two arguments. If the first argument is not NULL, the function returns the first argument. Otherwise, the second argument is returned. This function is commonly used to replace NULL value with another value.

SELECT IFNULL(Sales,’No data avilable’) FROM Sales_Data;


Have a nice day... 'N happy Coding :)