Total Pageviews

URL Rewriting in ASP.NET through IIS

Prerequisites

This walkthrough requires the following prerequisites:
  1. IIS 7 or above with ASP.NET role service enabled.
  2. URL Rewrite Module Go Live release installed.

Setting up a test Web page

To demonstrate how the URL Rewrite Module works, we will use a simple test ASP.NET page. This page reads the Web server variables and outputs their values in the browser.
Copy the following ASP.NET code and put it in the %SystemDrive%\inetpub\wwwroot\ folder in a file called article.aspx:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>URL Rewrite Module Test</title>
</head>
<body>
<h1>URL Rewrite Module Test Page</h1>
<table>
<tr>
<th>Server Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Original URL: </td>
<td><%= Request.ServerVariables["HTTP_X_ORIGINAL_URL"] %></td>
</tr>
<tr>
<td>Final URL: </td>
<td><%= Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] %></td>
</tr>
</table>
</body>
</html>

After copying this file, browse to http://localhost/article.aspx and check that the page was rendered correctly in a browser.

Creating a rewrite rule

We will create a simple rewrite rule that rewrites URLs by using the following format:
http://localhost/article/342/some-article-title
will be rewritten as:
http://localhost/article.aspx?id=342&title=some-article-title.
We will create a rewrite rule by using URL Rewrite UI in IIS Manager. To do this follow these steps:
  1. Go to IIS Manager.
  2. Select Default Web Site.
  3. In the Feature View click URL Rewrite.
  4. In the Actions pane on right-hand side, click Add rules…
  5. In the Add Rules dialog box, select the Blank Rule and click Ok.
Now you must define the actual rewrite rule. In the URL Rewrite Module, a rewrite rule is defined by specifying four required pieces of information:
  • Name of the rule.
  • Pattern to use for matching the URL string.
  • Optional set of conditions.
  • Action to perform if a pattern is matched and whether all conditions checks succeed.

Naming a rule

In the Name text box, enter a name that will uniquely identify the rule, for example: ”Rewrite to article.aspx”.

Defining a pattern

In the Pattern text box, enter the following string:
^article/([0-9]+)/([_0-9a-z-]+) This string is a regular expression that specifies that the pattern will match any URL string that meets the following conditions:
  1. Starts with the sequence of characters “article/”.
  2. Contains one or more numeric characters after the first “/”.
  3. Contains one or more alphanumeric or “_” or “-” characters after the second “/”.
Notice that certain parts of the regular expression are within parentheses. These parentheses create capture groups, which can be later referenced in the rule by using back-references.

Defining an action

Since the rule that we are creating is supposed to rewrite the URL, choose the Rewrite action type that is listed in the Action group box. In the Rewrite URL: text box, enter the following string:
article.aspx?id={R:1}&title={R:2} This string specifies the new value to which the input URL should be rewritten. Notice that for the values of the query string parameters we used {R:1} and {R:2}, which are back-references to the capture groups that were defined in the rule pattern by using parentheses.
Leave default values for all other settings. The Edit Rule property page should look like the following page:


Save the rule by clicking Apply on the right-hand side.

Viewing the rewrite rule in configuration file

The rewrite rules are stored either in the ApplicationHost.config file or in Web.config files. To check the configuration of the rule that we have just created, open a Web.config file located in %SystemDrive%\inetput\wwwroot\. In this file you should see the <rewrite> section that contains this rule definition:
<rewrite>
<rules>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
</rule>
</rules>
</rewrite>

Testing the rule

To test that the rule correctly rewrites URLs, open a Web browser and request the following URL:
http://localhost/article/234/some-title
You should see that the rewrite rule on your Web server has changed the original URL to Article.aspx and it has passed “234” and “some-title” as values for query string parameters.

Creating a redirect rule

Now we will create a redirect rule that will redirect all URLs in the following format:
http://localhost/blog/some-other-title/543
will be redirected to:
http://localhost/article/543/some-other-title
To do this, open the URL Rewrite feature view UI in IIS Manager and then click Add Rule… and then select the Blank Rule template again.
Within the Edit Rule page, enter the following:
  • Name: Redirect from blog (This is a unique name for the rule.)
  • Pattern: ^blog/([_0-9a-z-]+)/([0-9]+) (This pattern will match the URL string that starts with “blog” and captures the second and third segments of the URL into back-references.)
  • Action: Redirect (The redirect action will cause a redirect response to be sent back to the browser.)
  • Redirect URL: article/{R:2}/{R:1} (This substitution string will be used as a redirect URL; notice that it uses back-references to preserve and rearrange the original URL pieces captured during pattern match.)
Leave default values for all other settings. The Edit Rule property page should look like the following page:

Save the rule by clicking Apply on the right-hand side.

Testing the rule

To test that the rule redirects requests correctly, open a Web browser and request the following URL:
http://localhost/blog/some-other-title/323
You should see that the browser was redirected to http://localhost/article/323/some-other-title as a result of redirect rule execution and then the request was rewritten in accordance to the rewrite rule that you have created earlier.

Creating an access block rule

The third rule that we will create is used to block all requests made to a Web site if those requests do not have the host header set. This type of rule is useful when you want to prevent hacking attempts that are made by issuing HTTP requests against the IP address of the server instead of using the host name.
We will create this rule without using IIS Manager. Open the Web.config file and locate the <rewrite> section. Insert the following rule:
<rule name="Fail bad requests">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>
into the <rules> collection, so that it is a first rule in a collection. The <rewrite> section should look like the following code:
<rewrite>
<rules>
<rule name="Fail bad requests">
<match url=".*"/>
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="AbortRequest" />
</rule>
<rule name="Redirect from blog">
<match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
<action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" />
</rule>
<rule name="Rewrite to article.aspx">
<match url="^article/([0-9]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
</rule>
</rules>
</rewrite>

Let’s analyze the rule to understand what it does.
  • <match url=".*"/> This element says that the rule will match any URL string.
  • <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> This element adds a condition to the rule that retrieves the host header value by reading the server variable HTTP_HOST, matches it against the pattern “localhost” and then negates the result of matching. In other words, the condition verifies that the host header does not match “localhost.”
  • <action type="AbortRequest" /> This element tells the URL Rewrite Module to end the HTTP request.

Testing the rule

To test this rule, open a Web browser and make a request to http://127.0.0.1/article/234/some-title. What you should see is a browser that does not receive any response from the server. However, if you request http://localhost/article/234/some-title, then the Web server will respond successfully.

Summary

In this walkthrough you have learned how to configure URL rewrite rules by using IIS manager or by manually editing Web.config files. The rules that were created in this walkthrough demonstrated some of the important features of the URL Rewrite Module, such as regular expressions support and the ability to use HTTP headers and server variables to make rewriting decisions.

Source: IIS

Write and Earn for blogging

A total new way of blogging: Write and Earn/

buyblogreviews.com
myblogguest.com 
payperpost.com
 

Send Spam Free Bulk Email

Tips to send emails into the Inbox without getting spammed.

1) Domain name spam

What is it? If you own a domain name for a website you are probably getting domain name spam. Spammers use the whois database to obtain a list of most of the doman names in the world (ie .com, .net. org). The spammers expect most website owners to set up generic email addresses such as sales@... and info@... They simply send spam to all of the standard generic words at email every domain name in the world.
How to prevent it: Do not have a generic email address such as sales@ and info@. Instead have less usual addresses. Here is a list of all of the generric words (I am currently aware of) the spammers are using:
- info@
- mail@
- sales@
- contact@
- contacts@
- root@
- home@
- contacts@
- enquiries@
- webmaster@.
2) Get on the White Lists
Hotmail and Yahoo! both keep lists of approved senders. Once you're on that list, that means you'll almost always go into the inbox.

3)
"Drips"the Messages
S
pam filters at most email providers look to see how many messages you're sending at a time. If you're sending to a large list, even if you have a fast and efficient email sending server, have the server "drip" the messages out slowly.
4) Break Large Lists Down
There are many reasons to break large email lists down into smaller ones,

5)
Clean" Your Email List
Most, if not all, email providers' spam filters penalize your domain or IP with a higher spam score (meaning there's a higher possibility of your emails going to junk folder) if they see that you are sending emails to bad email accounts. A bad email account is an address that doesn't exist, has been disabled or has a full inbox.

6)
Become the ContactOnce a user has added you to his or her contact list, friend list or address book, you will always end up in their inbox.

7) Test Your Email
Before you send your entire email list the message you've worked so hard on, send a test message to each of the big email providers (Hotmail, Yahoo, MSN, Gmail, AOL and one generic office address that is viewed in an Outlook client). Send the test email using the exact same server and information that you'll use with your main list. If the test ends up with most of your emails going to junk folder, then it means you'll end up in the junk box on your main send also. The pre-send test means that you can try different subject lines and email content to try to figure out what sent you to spam.

8)
Don't Use "The Big Image"Embedding images in email is not totally a bad idea, but sending an email that's all one big image file definitely is, for many reasons. Foremost among reasons is that spam filters look for those types of image-based emails

9) Don't Sound Like a Spammer!
This one should be obvious! The more "spam-like" text and phrases your email uses, the less likely it is to end up in the inbox. There are a number of free software solutions to check the "spam score" of an email before you send it, but there are also basic rules.
  • Don't use the word "free" too many times.
  • Don't use ALL CAPS.
  • Don't use lots of colored fonts.
  • Only use one exclamation point at a time!
  • Stay away from words you'd see in spam: Viagra, drugs, porn, guaranteed winner.
10) Don't Have bad HTML Code
Spam filters check for bad html code, particularly if it looks like the code was done in Microsoft Word and then thrown into an email. Use a professional coder (preferably one who has done email templates before and knows the best way to make them resolve properly in an inbox) or a template provided by your email sending partner.
source: emailmarketing.comm100

Easy and Quick SEO Strategies


Onpage Analysis:
SWOT analysis of website,
Keyword research and analysis
Competition analysis
Target segmentation
Meta Tags Optimization
Robots.txt optimization
Canonical Tag Implementation
Image Optimization
Hyper link optimization
Header Tag Optimization
URL Rewriting
RSS Feed Creation
Google sitemap creation
Google Sitemap Submissions
Yahoo sitemap creation
Yahoo Sitemap Submissions
Google Analytics Setup
Landing Pages Optimization
Spider Friendly Navigation Setup
Google webmaster tools

Offpage Analysis
Submission to search
engines
Directory Submission
Article Submission
Forums Postings
Blog Commenting
Classifieds Submissions
Press Releases
Submissions
One Way Link Building

PPC
Website Analysis
Competitive Analysis
Account Setup
Tracking Code Setup
Ad Campaign Management
Keyword Research
Ad Groups Creation
Ad copy creation
A/B Ad Copy Testing
Geo Targeting
Local Search Campaigns
Day Parting
Budget Management
Bid Management
Landing page consultation
Ad Group Monitoring
Google Analytics code setup
Funnel Tracking
Traffic Statistics
Conversion Tracking
ROI Management

SMO 
Social Bookmarking
Social Media Networking
Content Distributions
Business Reviews
Video Optimization
Rss Feed Optimization
Using Facebook
Using Twitter
Using LinkedIn
Wikies
Consumer Generated Content
Apps. & Widgets
Bloging/Microbloging
PPT
Photo Sharing

Web Scrapping

There are several tools in market which can help you in scrapping data from the websites. Its not a legal way but you can do with a permission from the site, The commonly and popular used tool which has given good results is

Visual Web Ripper

URL Rewriting in ASP.NET

URL Rewriting with URLRewriter.Net Simplest Way

Do you have question? Ask any question related to asp.net programming and I will answer on this programming forum.
URL Rewriting with URLRewriter.Net

URL Rewriting has lots of benefits, listing its main benefits
  • SEO Friendly URL
  • Secured URL
  • No need to change bookmark with change in site structure.

Before URL Rewriting my URL looks like
http://localhost:2661/URLRewrite2/DynamicPage.aspx?MyTitleId=1

After URL Rewriting URL is changed to

http://localhost:2661/URLRewrite2/Article/Asp-Net-website-paths-1.aspx


Lets Understand URL Rewriting with Simple Example

A Website displaying articles list in a gridview on clicking the article link, it will display dynamically generated article content.

Before URL Rewriting when you mouse-over 1st Article Link, "Asp.net Website Path" it uses query string to display the article content.


Dynamic page display Querysting, before URL Rewriting.



After URL Rewriting we will achieve how SEO Friendly URL is used to display article content.


Now, lets understand how we can achieve it.

For URL Rewriting we are using URLRewriter.Net which is available free. Download URLRewriter.Net

Step-by-Step Explanation

Step 1: Download Binary Files for URLRewriter.Net

Step 2: Add Reference to Binary Files, Right click project "Add Reference" and add binary files.


Step 3: Update Web.Config File to make URLRewriter.Net works.
<configuration>

<configSections>
<section name="rewriter"
requirePermission="false"
type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
</configSections>

<system.web>

<httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" />
</httpModules>

</system.web>

<system.webServer>

<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule" />
</modules>

<validation validateIntegratedModeConfiguration="false" />

</system.webServer>

<rewriter>
<rewrite url="~/Article/(.+)-(.+).aspx" to="~/DynamicPage.aspx?MyTitleId=$2"/>
</rewriter>

</configuration>


Step 4: Adding Function to Generate SEO Friendly URL from given Title

public static string GenerateURL(object Title, object strId)
{
string strTitle = Title.ToString();

#region Generate SEO Friendly URL based on Title
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');

strTitle = strTitle.ToLower();
char[] chars = @"$%#@!*?;:~`+=()[]{}|\'<>,/^&"".".ToCharArray();
strTitle = strTitle.Replace("c#", "C-Sharp");
strTitle = strTitle.Replace("vb.net", "VB-Net");
strTitle = strTitle.Replace("asp.net", "Asp-Net");

//Replace . with - hyphen
strTitle = strTitle.Replace(".", "-");

//Replace Special-Characters
for (int i = 0; i < chars.Length; i++)
{
string strChar = chars.GetValue(i).ToString();
if (strTitle.Contains(strChar))
{
   strTitle = strTitle.Replace(strChar, string.Empty);
}
}

//Replace all spaces with one "-" hyphen
strTitle = strTitle.Replace(" ", "-");

//Replace multiple "-" hyphen with single "-" hyphen.
strTitle = strTitle.Replace("--", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("-----", "-");
strTitle = strTitle.Replace("----", "-");
strTitle = strTitle.Replace("---", "-");
strTitle = strTitle.Replace("--", "-");

//Run the code again...
//Trim Start and End Spaces.
strTitle = strTitle.Trim();

//Trim "-" Hyphen
strTitle = strTitle.Trim('-');
#endregion

//Append ID at the end of SEO Friendly URL
strTitle = "~/Article/" + strTitle + "-" + strId + ".aspx";

return strTitle;
}


Step 5: Changing DataBinder.Eval Function in .Aspx Page to reflect changes in URL of Grid.
Note: Learn more about DataBinder.Eval Function


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" CellPadding="3" CellSpacing="2" Width="788px">
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<Columns>
   <asp:TemplateField HeaderText="Title">
       <ItemTemplate>
           <asp:HyperLink ID="hlTitle" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Title")%>' NavigateUrl='<%#GenerateURL(DataBinder.Eval(Container.DataItem,"Title"),DataBinder.Eval(Container.DataItem,"Id"))%>'></asp:HyperLink>           
       </ItemTemplate>
   </asp:TemplateField>
   <asp:TemplateField HeaderText="Description">
       <ItemTemplate>
           <asp:Label ID="lblDesc" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Description")%>'></asp:Label>
       </ItemTemplate>
   </asp:TemplateField>
</Columns>
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />
</asp:GridView>


Now, Lets Check the stuff so far developed.

Assigning SEO Friendly URL in to grid.


On clicking URL inside grid it will point to Dynamically Generated Page with SEO Friendly URL, rather than QueryString.


Things to consider while URL Rewriting.

Problem 1: Page Postback, will turns User Friendly URL into Original URL.
Problem 2: CSS, Image Files pointing to URL Rewriting Page won't work, as they might be pointing with absolute path.

Problem 1: Page Postback for Page displaying URL Rewritten URL
Page Postback of Page displaying User friendly URL will turns into original state when same page postback occurs. In our example, I am adding one button and trying to make Page Postback. You will notice that Page Postback will turns the User Friendly URL into original URL containing QueryString.


For Resolving Page PostBack problem for Page displaying URL Rewritten URL

This article is inspired from Scott's URL Rewritten article. Adding two files as mentioned by scott. If you are developing code in VB download files from Scott's article, else for C# download files with Sourcecode at the end of this article.



Now, lets test the Page Postback by clicking on Button, you will notice this time, URL remains the same.




Problem 2: Image Display Problem
Now, lets display image on for this page and lets observe what problem we may run into. I have added following line to display image, but it won't works.
<img src="Images/article.gif" />


Resolve Problem, by refrencing file from root.
<img src="../Images/article.gif" />


Download Source-Code for URL Rewriting
 
 
source:dotnetguts