Monday, August 1, 2011

Ajax Minifier reduces the size of javascript and css files

Ajax Minifier is a Microsoft program which mifys js and css files. Minification is the process of reducing the size of a CSS or JS file by removing whitespaces, comments and other optimization. This is a free tool and it can be used in command line or MSBuild tasks.

The idea behind this tool is to improve the load time whenever the site is requested. Most of the times, about 70-90% of time spent waiting for a page on the average web site is actually due to the number of HTTP requests for images, JS and CSS files. To improve this, we can use this tool and it minify's the css, js files so that the download time will be considerably lesser than the actual file.

So whenever you trigger a new build from visual studio its going to execute a build and before moving that build to deployment server its going to execute this build task to minify and combine the css and javascript files in your site as mentioned by you in the target folder. After combining, its going to creat a single javascript and a single css file for entire site and name it with this version of build.

When the user requests for your site on the next time the name of previous js file and this js file is going to be different because of this version number change and the browser is going to download it to local cahe, so for subsequent requests it will use it from the cache. This is how it makes the site very faster.

Ranking Functions in Sql Server 2008

There are four ranking functions in sql server. They are Row_Number(), Rank(), Dense_Rank(), Ntile().

Row_Number()

Row_Number function gives the sequential order of numbers starting from 1 for the specified row. This function is used to split the table based on this row number.


 
select *, ROW_NUMBER() over(partition by part order by value) AS Partition
from Ranker

Rank()

Rank() function consider the repeating values in the column. If two values are same in the column means both values are given the same rank and the next value gets the respected rank.

Dense_Rank()

Dense_Rank() is as same as rank function the only difference is the next value to the repeating value should take the rank in sequence order.

Ntile()

Ntile() function is different from others. It splits the table based on the given range and rank the number for the partitions.



create table Ranker(value int)

Insert into Ranker values(8),(1),(6),(2),(3),(6),(4),(5),(8),(9),(3),(7)

select *,
	ROW_NUMBER() over(order by value) AS Row_No,
	RANK() over(order by value) AS Rank ,
	DENSE_RANK() over(order by value) AS Dense_Rank,
	NTILE(4) over(order by value) AS Ntile
from Ranker  
 
 
Value	Row_No	Rank	D_Rank	Ntile
1	1	1	1	1
2	2	2	2	1
3	3	3	3	1
3	4	3	3	2
4	5	5	4	2
5	6	6	5	2
6	7	7	6	3
6	8	7	6	3
7	9	9	7	3
8	10	10	8	4
8	11	10	8	4
9	12	12	9	4


Sunday, March 20, 2011

Configure Secure Socket Layer (SSL) in IIS 7 or IIS 7.5 in Windows 7

HTTPS is a secure communications channel that is used to exchange sensitive information like User Credentials, Credit Card details etc. between a client computer and a server. It uses SSL which encrypts communication over a network like the internet.

In this article, we will see how to configure Secure Socket Layer (SSL) in IIS 7.x in a Windows 7 machine. To enable SSL in IIS, you must first obtain a certificate that is used to encrypt and decrypt the information transferred over a network.

I assume you have configured IIS 7 on your Windows 7 box and have ASP.NET registered on your IIS server. If you have not yet configured IIS on your Windows 7 box, I strongly suggest you to read these two posts before continuing further

Install IIS 7 on Windows 7

Resolving ASP.NET 4.0 has not been Registered on the Web Server Error

Assuming you are all set, go to Start > All Programs > Accessories > Run. Type Inetmgr and hit enter. This opens up the IIS Manager. In the IIS Manager > Select the root node > Double click ‘Server Certificates’

IIS Server Certificates

If you have a list of Server Certificates installed on your server, you will be able to view them now. But it happens that I do not have any on my server. In that I can either ‘Create Certificate Request’ or use a ‘Self-Signed Certificate’ for testing purpose.

Self Signed Certificate

Note: If you choose the ‘Create Certificate Request’ option, IIS creates a Base64 encoded request. You can then submit this request to a Certificate Authority (like Verisign) and receive a SSL certificate which can be registered on your web server using the ‘Complete Certificate Request’ that you see in the screenshot above.

However if you choose the ‘Create Self-Signed certificate option, then IIS creates a self-signed certificate for your own server. It is an easy option if you plan to use HTTPS for local testing purpose. Remember that you can access this certificate only from your machine.

We will go ahead with creating a Self-Signed certificate for testing purpose. Click the ‘Create Self-Signed certificate’ link > Enter a friendly name for the certificate request and hit OK.

Self Signed Certificate Name

As you can see in the screenshot below, we have a self-signed certificate that we can use for testing purpose.

Sample Cert

The last step is to set the protocol for SSL for your website. To do so, select your website in the IIS Manager > In the Action pane, select Bindings > Add Site Binding

Https Site Binding

Select the Type https and ‘SampleCert’ as SSL certificate and click OK

AddIis Site Binding

Your Website is now SSL enabled. To test, type https://localhost/YourSiteName and you should be able to see the default page.

I hope you liked the article and I thank you for viewing it.

Friday, March 4, 2011

Difference between WPF and WCF in .Net

Window presentation foundation (WPF)is to help developers create attractive and effective user interfaces. The WPF is included in version 3.0 of the Microsoft .NET Framework, allows building interfaces that incorporate documents, media, two- and three-dimensional graphics, animations, Web-like characteristics, and much more.

Wherein,Windows Communication Foundation (WCF) is a framework for distributed programming. The WCF is designed to offer a manageable approach to distributed computing, broad interoperability, and direct support for service orientation. It includes serialization facilities that enable loose coupling and versioning, and it provides integration and interoperability with existing .NET Framework distributed systems technologies such as Message Queuing (MSMQ), COM+, ASP.NET Web services, Web Services Enhancements (WSE), and a number of other functions.

Convert Time in Different TimeZones in ASP.NET

In this article, we will see how to convert time from one time zone to another, in an ASP.NET application.
Step 1: Fire up Visual Studio > File > New Website. Drag and drop a DropDownList and two Label controls to the page and add a ‘SelectedIndexChanged’ event to the DropDownList (we will code this event later). The DropDownList will display the different Timezones and the Label controls will display the Local time as well as the Converted time. Here’s how the markup would look like.
<form id="form1" runat="server">
<div>
<asp:DropDownList ID="ddlTimeZone" runat="server" AutoPostBack="True"
onselectedindexchanged="ddlTimeZone_SelectedIndexChanged"
AppendDataBoundItems="true" >
<asp:ListItem Text="Select a TimeZone" Value="Default value" />
asp:DropDownList>
<br /><br />
Local Time: <asp:Label ID="lblLocalTime" runat="server" Text="">asp:Label>
<br /><br />
Converted Time: <asp:Label ID="lblTimeZone" runat="server" Text="">asp:Label>
div>
form>
Step 2: We will now populate the DropDownList with the different TimeZones available. A simple way to do that is to use the TimeZoneInfo.GetSystemTimeZones method. This method returns a generic ReadOnlyCollection(Of T) collection of TimeZoneInfo objects.
Write the following code in the Page_Load method
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
lblLocalTime.Text = DateTime.Now.ToString();
ReadOnlyCollection<TimeZoneInfo> tzi;
tzi = TimeZoneInfo.GetSystemTimeZones();
foreach (TimeZoneInfo timeZone in tzi)
{
ddlTimeZone.Items.Add(new ListItem(timeZone.DisplayName, timeZone.Id));
}
}
}
VB.NET (Converted Code)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
lblLocalTime.Text = Date.Now.ToString()
Dim tzi As ReadOnlyCollection(Of TimeZoneInfo)
tzi = TimeZoneInfo.GetSystemTimeZones()
For Each timeZone As TimeZoneInfo In tzi
ddlTimeZone.Items.Add(New ListItem(timeZone.DisplayName, timeZone.Id))
Next timeZone
End If
End Sub
As you can see, we first extract the different TimeZones available on the machine using TimeZoneInfo.GetSystemTimeZones and then loop through the collection and add the name and value to the DropDownList. The TimeZoneInfo.DisplayName is the Name and the TimeZoneInfo.Id is the value added to the DropDownList.
image_2
Step 3: The last step is to convert the local time into the TimeZone selected by the user in the DropDownList. We will do the conversion using the TimeZoneInfo.ConvertTimeBySystemTimeZoneId. This method converts a time from one time zone to another based on the ‘time zone identifier’ without the need to know whether the converted time is standard or daylight saving time. Remember we used the TimeZoneInfo.Id that formed the ‘value’ of the DropDownList in Step 2. We will use that value here as shown below:
C#
protected void ddlTimeZone_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlTimeZone.SelectedIndex > 0)
{
DateTime dt = DateTime.Now;
lblTimeZone.Text = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt,
TimeZoneInfo.Local.Id, ddlTimeZone.SelectedValue).ToString();
}
}
VB.NET (Converted Code)
Protected Sub ddlTimeZone_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If ddlTimeZone.SelectedIndex > 0 Then
Dim dt As Date = Date.Now
lblTimeZone.Text = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dt, TimeZoneInfo.Local.Id, ddlTimeZone.SelectedValue).ToString()
End If
End Sub
That’s it. Run the application and convert the local time into the desired TimeZone as shown below
image_1

Tuesday, February 8, 2011

SQL DISTINCT on Multiple Columns

The DISTINCT clause works in combination with SELECT and gives you unique date from a database table or tables. The syntax for DISTINCT is show below

SELECT DISTINCT "column_name"
FROM "table_name"

If you want a DISTINCT combination of more than one column then the syntax is

SELECT DISTINCT column1, column2
FROM "table_name"

Let's look at some examples to understand the usage of the DISTINCT keyword. First, let's create a table for our illustration and insert some data.

CREATE TABLE DuplicateTest(
Firstname
nvarchar (30) NOT NULL,
Lastname
nvarchar(30) NOT NULL,
PostalCode
nvarchar(15) NOT NULL,
City
nvarchar(30) NOT NULL
)
insert into DuplicateTest
(Firstname,Lastname,PostalCode,City)
values
('Param', 'Singh', 'B283SP', 'Birmingham'),
('Steve', 'White', 'EC224HQ', 'London'),
('Mark', 'Smith', 'L324JK', 'Liverpool'),
('Claire', 'whitehood', 'M236DM', 'Manchester'),
('Param', 'Singh', 'B283SP', 'Birmingham')

select * from DistinctTutorial
DuplicateTest
Firstname Lastname PostalCode City
Sarvesh Singh B263SP Birmingham
Steve White EC224HQ London
Mark Smith L324JK Liverpool
Claire whitehood M236DM Manchester
Param Singh B283SP Birmingham

In the result set above there are repetitions in the City Column. Let's get a list of all cities without repeating them using DISTINCT.

select DISTINCT City from DuplicateTest
City
Birmingham
Liverpool
London

Manchester


You can see 'Birmingham' is just returned once in this result, even though it appears more than once in the table. You can get the same result using GROUP BY as shown below.

select city from DuplicateTest
group by city

Let's now use DISTINCT with more than one column. We will add the Lastname column in as well.

select DISTINCT City,Lastname from DuplicateTest
Distinct City and lastname
City Lastname
Birmingham Singh
Liverpool Smith
London White
Manchester whitehood

We get a list of results that have multiple rows, none of which are duplicated.

Again, you can get the same result by using GROUP BY as shown below:

select city,lastname from DuplicateTest
group by city, lastname

If you look at the original data, there are two users with same Lastname (Singh) who live in the same city (Birmingham). With the DISTICT keyword you get one unique row. Let's now add another column to our SELECT query.

select DISTINCT City,Lastname,Postalcode from DuplicateTest

This returns:

City Lastname PostalCode
Birmingham Singh B263SP
Birmingham Singh B283SP
Liverpool Smith L324JK
London White EC224HQ
Manchester whitehood M236DM

You will notice now that you are seeing two rows with the same lastname of Singh. This is because their 'Postalcode' is different, and the addition of that column makes the rows unique.

Again you will get the same result using GROUP BY as shown below:


select city, lastname, postalcode
from DuplicateTest
group by city, lastname, postalcode

Let's look at another example where you can use DISTINCT on multiple columns to find duplicate addreses. I've taken this example from the post. Please refer to this post for more detail.

SELECT PostCode, COUNT(Postcode)
FROM
(
SELECT DISTINCT Address1, Address2, City, Postcode
FROM AddressTable
) AS Sub
GROUP BY Postcode
HAVING COUNT(Postcode) > 1

Or you can use GROUP BY as follows:

SELECT Address1,Address2,City,PostCode,Count(PostCode)
FROM AddressTable
GROUP BY Address1,Address2,City,PostCode
HAVING Count(PostCode) > 1

In both of these cases, we are using DISTINCT to find those rows that are duplicates, based on the columns we include in the queries.

DISTINCT can also be used to get unique column values with an aggregate function. In the example below, the query gets the unique values of reorderpoint and then does a SUM.

USE AdventureWorks
GO
SELECT SUM(DISTINCT ReorderPoint) as DistinctSum
FROM Production.Product
GO

Result: 1848 rows

In the example below query is doing a SUM of ReorderPoint including the duplicates.

SELECT SUM(ReorderPoint) as WithoutDistinct
FROM Production.Product
GO

Result: 202287 rows

As you can see from the above two examples the importance of DISTINCT with an aggregate function. The user could end up un-knowingly using completely incorrect SUM had he used the result from the second query if the requirement was to get the SUM of unique values of ReorderPoint.

The purpose of the article was to show a user simple usage of DISTINCT. I hope you would find this article useful.

Sunday, September 19, 2010

Good Backlinks for your website

What are Backlinks?
Backlinks are links on other websites pointing at your website. Without adequate links pointing at your website it will likely never achieve higher keyword ranking.
How to Find Good Backlinks
Website ranking involves more than just putting your website online. The old addage, "Build it and they will come" is no longer true. You need to not only have quality content on your website but also focus on getting good backlinks but also relevant backlinks. The kind of links you gather and where the link is placed on the other site will also determine the amount of traffic you get and your ranking in the search engines.

Google and Yahoo rank websites according to how many quality backlinks they find pointing at your website. Quality is determined by how relevant the other site is to your site and where the link is placed on their page (within the content is best) and how many other links are on the page (less is better). A large number of links pointing at your site does not guarantee success. You need quality backlinks in order to rise to the first page of results and the more you can find the better.

Google started devaluing traded links in Fall of 2007 and started penalizing directories that used dishonest means to raise their own PR so they could sell links. Google penalized those directories by dropping their PR (Page Rank) to Zero and Keyword Rank so far that they didn't even rank for their own business name. This also affected the rank of sites that bought links from those directories because their link count dropped.

If you have been buying links from directories and your PR or keyword rank is dropping it may be because of Google penalizing those directories. This causes those sites to put rel="nofollow" on the links to protect themselves, thus you are no longer credited for those links you bought which reduces your PR and thus your Keyword Rank.

Google also penalizes sites for getting involved in Triangular Linking Schemes, i.e., "I'll link to your site from my site if you link to my other site" (they do this so it doesn't look like a link trade but Google knows how to spot these also).

Therefore the best way to encourage people to link to your content is to provide information that is useful to your visitors.

What are Quality Backlinks?

* Few links on a page
* A link within the body content
* Link from a relevant site

Google recently changed it's algorighym so that if there is an excess of traded links, purchased links, or if you get involved in triangular linking schemes, or buy hundreds or thousands of links all at once, then it will draw a red flag for Google and then Google may apply a filter to your site to prevent it from ranking well.

An occasional, relevant link trade is ok and having to buy a link in Yahoo directory or another directory that is human reviewed where you have to pay for the review (and not the submission) is OK, but anything in exess can cause you problems with your ranking in Google because they can tell when link gathering is not normal.

Google is having to do this due to too many finding some new trick that helps their keyword rank (like hidden text) and then everyone else follows suit and then Google has to clamp down on that practice — until next time someone comes up with a "bright idea".

So anything you do to try and manipulate your rank in Google can draw a red flag and your site could be banned, penalized or have your keyword rank filtered out, i.e., you won't be able to rank for anything no matter what you do.

Best Linking Practice
The best, and easiest, method to gather links is to provide something on your website that people will want to link to, i.e., if you build bridges offer free bridge building plans, if you sell dessert products offer free recipies of products you don't offer, if you provide a service write up a FAQ about your service, etc. You can also provide a service or product for free if they will provide a backlink to your site . On LWD, I provide a lot of HTML tips, Css Tips, graphics tutorials and articles on keyword ranking and other topics which bring in a lot of my traffic and backlinks without my even asking.

Finding Backlinks For Your Website
Find friends, businesses, individuals, or organizations who are willing to link to your website as soon as it's online, then you won't need to submit to search engines because the search engines can find your link on a site they have indexed already. Some of them may require a link trade but try to get mostly one-way links.

Find Good Backlinks
Google uses age of the site, backlinks as well as PR to rank sites (along with many other factors) so, unless you want to PayPerClick for the life of the site, you need to get gather a lot of links and write a lot of content to get rank as high as possible.

Look for websites relevant to what your site offers but have a different focus, i.e., submit to a gardening site if you sell garden tools.

Another way to find good backlinks is to search for your major keyword in your favorite search engine and take note of which of your competitors is ranking highest. Then search for their domain name and look for sites that have accepted their link then try and submit your website there also.
Other Methods of Getting Good Backlinks

* Find Directories in Your Own Niche Submit to directories in your own niche, i.e., if you sell or offer information about vitamins then look for directories focused on health products.

* Free Submission Directories If you aim for free submissions from directories you may need to request about 10 times as many backlinks as you actually need as very few free links are accepted by directories claiming to accept free submissions. They do this so they won't be penalized for only offering paid links. When submitting, change your anchor text (title of your site) frequently so there is a wide variety of keywords to rank for, however you will probably have to pay for anything other than your official site name.

Also see:
Directories that Pass PR
and
Directories to Avoid
* Write Articles Write quality articles related to the focus of your website and submit to other sites. Provide a link within the article to your site related to the focus in the article -- not necessarily your home page. Do NOT post the same article on your own website or you may be penalized for duplicate content.

* Submit Press Releases Only submit press releases when you have a valid reason for one--any new development on your site or an original focus with your products that the customers on the press release will be interested in.

* Blogging Set up a blog on a separate site related to the topic of your site and provide information of value to your visitors (that you don't provide on your own site) with a link to your website within the post where appropriate. Don't link from your website to your blog or it will be discounted.

* Participate in Forums Find forums related to your website's focus and post often so you will get noticed and build up trust so people will click on the link in your profile or signature and possibly link to your site from their own site or in other forums showing where they found valuable information. Most forums now put a rel="nofollow" on all outgoing links so this may not benefit you other than getting some traffic.

How Many Backlinks is Enough?
That depends on your major keywords. Are they popular? If so, you will have a struggle to beat your competition and may have to resort to PayPerClick along with backlinks.

If very few websites advertise what you offer then you may not need very many backlinks to rank high in the search engines but your traffic may still be minimal because of your site being so specialized. In that case diversify and add more information.

Getting Backlinks is an On-going Process
Your backlinks need to be replenished each year because some sites along with their backlinks go offline. Your competitors are probably eagerly seeking more backlinks to outrank you so unless you actively seek more backlinks each year your rank may drop.

Also see
Backlinks to Avoid
and
Keyword Ranking Strategy
Pay Per Click is only temporary
Getting good quality backlinks is a lengthy process and can take several months--unless you want to utilize PayPerClick (Google's AdWords) and then it can achieve almost immediate results but those results will end as soon as you quit paying so it's a good idea to gather links at the same time.

If you would like your web site analyzed for keyword ranking please check out the Website Evaluations page. If you are looking for a web designer see the How to Find a Web Designer page first.