Web Hosting Tutorials

Bookmark Us

Web Hosting
The options for web hosting these days are enormous, with types such as shared, dedicated, 
co-located, VPS and reseller multiplied by the plethora of differing operating systems, scripting
 languages and hardware choices. Read on to find the answer to your questions.



Url Rewriting in IIS-7
Windows
Friday, 05 June 2009 21:21
URL's - Why should we care?

As web applications get more sophisticated, programmers begin to demand finer control over all aspects of their creation. This trend has now extended to the ubiquitous Uniform Resource Locator (URL) that is used in the address bar of every browser.

We are all familiar with complex URL's filled with question marks, strange symbols, and numbers. How many times have you needed to write down a URL simply so that you can reproduce it carefully at a later date? For example, if the URL is in an image file, you'll have to type it into the browser by hand. And God help you if it's dozens of characters long!

But apart from this, URL's that are complex are bad for business because Internet users aren't able to easily remember the page that they visited once and forgot to bookmark. Humans don't remember meaningless symbols and it is in the interests of web designers to ensure that their URL's make sense - to get an example, just look at any Wikipedia article.

Other uses of clean URL's are to improve the search engine friendliness of the site so that you can insert important keywords into it, as well giving the Internet user the flexibility of directly going to a URL because it makes sense - also called "hackability"

IIS 7 and the URL Rewrite Module.

In a lot of cases, it's easy to keep good URL's with proper site development. But what if your site already has messy URL's and rewriting or restructuring the application is not feasible?

IIS 7's new features allows web developers to convert existing messy URL's into simpler ones. This is made even easier with the .NET framework. They allow tremendous flexibility in the ability to rewrite URL's to cover a variety of situations.

For example, suppose you have recently redesigned the folder structure of your website you will be stuck with a lot of broken links. To make matters worse, lots of customers could have bookmarked the pages that have moved leading to a potential loss of business. IIS 7 now allows you to detect such requests and perform a seamless redirection to the new pages. It allows you to create matching rules based on regular expressions or wild cards that give you unparalleled flexibility in changing URL's to suit your needs.

One of the coolest possibilities is to completely rewrite a URL so that what the customer sees in the address bar makes sense - without that page even existing in the first place! What this means is that suppose the customer is viewing the list of books by a particular author. This author is identified internally in your database with a number and the querystring in the URL reflects that. However, such a URL makes no sense to a user who will not remember the URL if he or she forgets to bookmark it.

With the new features in IIS 7, you can have a URL that reads ".../europe/dickens" instead of ".../display?authorid=89&continentID=2" . Unknown to the user, the first URL may not actually exist physically on the server! But when they type it into the browser address bar, they get what they expect to see.

These exciting developments have only just emerged along with improvements to the IIS 7 engine. Another reason to choose a Windows Hosting service!
 
For more Information on IIS7 Hosting 


Last Updated on Saturday, 13 June 2009 22:46
 
URL Rewriting with ASP.net
Windows
Friday, 05 June 2009 21:16
Why is URL rewriting so important
 
One of the most important reasons is one of accessabilty, inaddition URL rewriting allows you to use key word revevant urls which will greatly improve your search engine relevancy. Moving from using querystring arguments to instead use fully qualified URL's can also in some cases increase your priority in search engine results.  Using techniques that force referring links to use the same case and URL entrypoint can also avoid diluting your pagerank across multiple URLs, and increase your search results.

In a world where search engines increasingly drive traffic to sites, extracting any little improvement in your page ranking can yield very good ROI to your business.  Increasingly this is driving developers to use URL-Rewriting and other SEO (search engine optimization) techniques to optimize sites (note that SEO is a fast moving space, and the recommendations for increasing your search relevancy evolve monthly).  For a list of some good search engine optimization suggestions, I'd recommend reading the SSW Rules to Better Google Rankings, as well as MarketPosition's article on how URLs can affect top search engine ranking.
Sample URL Rewriting Scenario

For the purpose of this blog post, I'm going to assume we are building a set of e-commerce catalog pages within an application, and that the products are organized by categories (for example: books, videos, CDs, DVDs, etc).

Let's assume that we initially have a page called "Products.aspx" that takes a category name as a querystring argument, and filters the products accordingly.  The corresponding URLs to this Products.aspx page look like this:
 
http://www.store.com/products.aspx?category=books
http://www.store.com/products.aspx?category=DVDs
http://www.store.com/products.aspx?category=CDs

Rather than use a querystring to expose each category, we want to modify the application so that each product category looks like a unique URL to a search engine, and has the category keyword embedded in the actual URL (and not as a querystring argument).  We'll spend the rest of this blog post going over 4 different approaches that we could take to achieve this.

Approach 1: Use Request.PathInfo Parameters Instead of QueryStrings

The first approach I'm going to demonstrate doesn't use Url-Rewriting at all, and instead uses a little-known feature of ASP.NET - the Request.PathInfo property.  To help explain the usefulness of this property, consider the below URL scenario for our e-commerce store:
 
http://www.store.com/products.aspx/Books
http://www.store.com/products.aspx/DVDs
http://www.store.com/products.aspx/CDs

One thing you'll notice with the above URLs is that they no longer have Querystring values - instead the category parameter value is appended on to the URL as a trailing /param value after the Products.aspx page handler name.  An automated search engine crawler will then interpret these URLs as three different URLs, and not as one URL with three different input values (search engines ignore the filename extension and just treat it as another character within the URL). 

You might wonder how you handle this appended parameter scenario within ASP.NET.  The good news is that it is pretty simple.  Simply use the Request.PathInfo property, which will return the content immediately following the products.aspx portion of the URL.  So for the above URLs, Request.PathInfo would return "/Books", "/DVDs", and "/CDs" (in case you are wondering, the Request.Path property would return "/products.aspx").

You could then easily write a function to retrieve the category like so (the below function strips out the leading slash and returning just "Books", "DVDs" or "CDs"):

    Function GetCategory() As String

        If (Request.PathInfo.Length = 0) Then
            Return ""
        Else
            Return Request.PathInfo.Substring(1)
        End If

    End Function
  
Approach 2: Using an HttpModule to Perform URL Rewriting

An alternative approach to the above Request.PathInfo technique would be to take advantage of the HttpContext.RewritePath() method that ASP.NET provides.  This method allows a developer to dynamically rewrite the processing path of an incoming URL, and for ASP.NET to then continue executing the request using the newly re-written path.

For example, we could choose to expose the following URLs to the public:

http://www.store.com/products/Books.aspx
http://www.store.com/products/DVDs.aspx
http://www.store.com/products/CDs.aspx

This looks to the outside world like there are three separate pages on the site (and will look great to a search crawler).  By using the HttpContext.RewritePath() method we can dynamically re-write the incoming URLs when they first reach the server to instead call a single Products.aspx page that takes the category name as a Querystring or PathInfo parameter instead.  For example, we could use an an Application_BeginRequest event in Global.asax like so to do this:
 
    void Application_BeginRequest(object sender, EventArgs e) {

        string fullOrigionalpath = Request.Url.ToString();
        
        if (fullOrigionalpath.Contains("/Products/Books.aspx")) {
            Context.RewritePath("/Products.aspx?Category=Books");
        }
        else if (fullOrigionalpath.Contains("/Products/DVDs.aspx")) {
            Context.RewritePath("/Products.aspx?Category=DVDs");
        }
    } 

The downside of manually writing code like above is that it can be tedious and error prone.  Rather than do it yourself, I'd recommend using one of the already built HttpModules available on the web for free to perform this work for you.  Here a few free ones that you can download and use today:

    * UrlRewriter.net
    * UrlRewriting.net

These modules allow you to declaratively express matching rules within your application's web.config file.  For example, to use the UrlRewriter.Net module within your application's web.config file to map the above URLs to a single Products.aspx page, we could simply add this web.config file to our application (no code is required):

             requirePermission="false" 
             type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

The HttpModule URL rewriters above also add support for regular expression and URL pattern matching (to avoid you having to hard-code every URL in your web.config file).  So instead of hard-coding the category list, you could re-write the rules like below to dynamically pull the category from the URL for any "/products/[category].aspx" combination:

This makes your code much cleaner and super extensible.

Sample Download: A sample application that I've built that shows using this technique with the UrlRewriter.Net module can be downloaded here. 

What is nice about this sample and technique is that no server configuration changes are required in order to deploy an ASP.NET application using this approach.  It will also work fine in a medium trust shared hosting environment (just ftp/xcopy to the remote server and you are good to go - no installation required).
Approach 3: Using an HttpModule to Perform Extension-Less URL Rewriting with IIS7

The above HttpModule approach works great for scenarios where the URL you are re-writing has a .aspx extension, or another file extension that is configured to be processed by ASP.NET.  When you do this no custom server configuration is required - you can just copy your web application up to a remote server and it will work fine.

There are times, though, when you want the URL to re-write to either have a non-ASP.NET file extension (for example: .jpg, .gif, or .htm) or no file-extension at all.  For example, we might want to expose these URLs as our public catalog pages (note they have no .aspx extension):

http://www.store.com/products/Books
http://www.store.com/products/DVDs
http://www.store.com/products/CDs

With IIS5 and IIS6, processing the above URLs using ASP.NET is not super easy.  IIS 5/6 makes it hard to perform URL rewriting on these types of URLs within ISAPI Extensions (which is how ASP.NET is implemented). Instead you need to perform the rewriting earlier in the IIS request pipeline using an ISAPI Filter.  I'll show how to-do this on IIS5/6 in the Approach 4 section below.

The good news, though, is that IIS 7.0 makes handling these types of scenarios super easy.  You can now have an HttpModule execute anywhere within the IIS request pipeline - which means you can use the URLRewriter module above to process and rewrite extension-less URLs (or even URLs with a .asp, .php, or .jsp extension).  Below is how you would configure this with IIS7:



  
    
             requirePermission="false" 
             type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />

Note the "runAllManagedModulesForAllRequests" attribute that is set to true on the section within .  This will ensure that the UrlRewriter.Net module from Intelligencia, which was written before IIS7 shipped, will be called and have a chance to re-write all URL requests to the server (including for folders).  What is really cool about the above web.config file is that:

1) It will work on any IIS 7.0 machine.  You don't need an administrator to enable anything on the remote host.  It will also work in medium trust shared hosting scenarios.

2) Because I've configured the UrlRewriter in both the and IIS7 section, I can use the same URL Rewriting rules for both the built-in VS web-server (aka Cassini) as well as on IIS7.  Both fully support extension-less URLRewriting.  This makes testing and development really easy.

IIS 7.0 server will ship later this year as part of Windows Longhorn Server, and will support a go-live license with the Beta3 release in a few weeks.  Because of all the new hosting features that have been added to IIS7, we expect hosters to start aggressively offering IIS7 accounts relatively quickly - which means you should be able to start to take advantage of the above extension-less rewriting support soon.  We'll also be shipping a Microsoft supported URL-Rewriting module in the IIS7 RTM timeframe that will be available for free as well that you'll be able to use on IIS7, and which will provide nice support for advanced re-writing scenarios for all content on your web-server.

Sample Download: A sample application that I've built that shows using this extension-less URL technique with IIS7 and the UrlRewriter.Net module can be downloaded here. 
Approach 4: ISAPIRewrite to enable Extension-less URL Rewriting for IIS5 and IIS6

I actually don't have any first-hand experience using either of the above solutions - although I've heard good things about them.  Scott Hanselman and Jeff Atwood recently both wrote up great blog posts about their experiences using them, and also provided some samples of how to configure the rules for them.  The rules for Helicon Tech's ISAPI Rewrite use the same syntax as Apache's mod_rewrite.  For example (taken from Jeff's blog post):

[ISAPI_Rewrite]
# fix missing slash on folders
# note, this assumes we have no folders with periods!
RewriteCond Host: (.*)
RewriteRule ([^.?]+[^.?/]) http\://$1$2/ [RP]

# remove index pages from URLs
RewriteRule (.*)/default.htm$ $1/ [I,RP]
RewriteRule (.*)/default.aspx$ $1/ [I,RP]
RewriteRule (.*)/index.htm$ $1/ [I,RP]
RewriteRule (.*)/index.html$ $1/ [I,RP]

# force proper www. prefix on all requests
RewriteCond %HTTP_HOST ^test\.com [I]
RewriteRule ^/(.*) http://www.test.com/$1 [RP]

# only allow whitelisted referers to hotlink images
RewriteCond Referer: (?!http://(?:www\.good\.com|www\.better\.com)).+
RewriteRule .*\.(?:gif|jpg|jpeg|png) /images/block.jpg [I,O]

One gotcha that people often run into when using ASP.NET and Url-Rewriting has to-do with handling postback scenarios.  Specifically, when you place a control on a page, ASP.NET will automatically by default output the "action" attribute of the markup to point back to the page it is on.  The problem when using URL-Rewriting is that the URL that the control renders is not the original URL of the request (for example: /products/books), but rather the re-written one (for example: /products.aspx?category=books).  This means that when you do a postback to the server, the URL will not be your nice clean one.

With ASP.NET 1.0 and 1.1, people often resorted to sub-classing the control and created their own control that correctly output the action to use.  While this works, it ends up being a little messy - since it means you have to update all of your pages to use this alternate form control, and it can sometimes have problems with the Visual Studio WYSIWYG designer.

The good news is that with ASP.NET 2.0, there is a cleaner trick that you can use to rewrite the "action" attribute on the control.  Specifically, you can take advantage of the new ASP.NET 2.0 Control Adapter extensibility architecture to customize the rendering of the control, and override its "action" attribute value with a value you provide.  This doesn't require you to change any code in your .aspx pages.  Instead, just add a .browser file to your /app_browsers folder that registers a Control Adapter class to use to output the new "action" attribute:

You can see a sample implementation I created that shows how to implement a Form Control Adapter that works with URLRewriting in my sample here.  It works for both the Request.PathInfo and UrlRewriter.Net module approaches I used in Approach 1 and 2 above, and uses the Request.RawUrl property to retrieve the original, un-rewritten, URL to render.  With the ISAPIRewrite filter in Approach 4 you can retrieve the Request.ServerVariables["HTTP_X_REWRITE_URL"] value that the ISAPI filter uses to save the original URL instead.

My FormRewriter class implementation above should work for both standard ASP.NET and ASP.NET AJAX 1.0 pages (let me know if you run into any issues).
Handling CSS and Image Reference Correctly

One gotcha that people sometime run into when using Url Rewriting for the very first time is that they find that their image and CSS stylesheet references sometimes seem to stop working.  This is because they have relative references to these files within their HTML pages - and when you start to re-write URLs within an application you need to be aware that the browser will often be requesting files in different logical hierarchy levels than what is really stored on the server.

For example, if our /products.aspx page above had a relative reference to "logo.jpg" in the .aspx page, but was requested via the /products/books.aspx url, then the browser will send a request for /products/logo.jpg instead of /logo.jpg when it renders the page.  To reference this file correctly, make sure you root qualify CSS and Image references ("/style.css" instead of "style.css").  For ASP.NET controls, you can also use the ~ syntax to reference files from the root of the application.


Last Updated on Saturday, 13 June 2009 22:46
 
Installing IIS7 in Vista
Windows
Thursday, 04 June 2009 20:52
If you are running a small workgroup of computers, you may want to use a computer running Windows Vista as a Web server for ASP.NET development. 

You can do so by installing Internet Information Services (IIS).By default, IIS 7.0 is not installed on Windows Vista® Business or Windows Vista® Ultimate.It provides for basic Web server functionality and includes the WWW, FTP, NNTP, and SMTP services.If you want to install IIS server you need to have vista business or ultimate editions.

You can install IIS using the following steps

Click Start—>Click Control Panel

Now Click Programs

Click Programs and Features

Select Windows features on or off from the left column

In the Windows Features dialog box, click Internet Information Services and then click OK.

Installation is in progress

Install IIS 7 Using script

• Type the following command into a script:

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;
IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HttpRedirect;
IIS-ApplicationDevelopment;IIS-ASPNET;IIS-NetFxExtensibility;IIS-ASP;IIS-CGI;
IIS-ISAPIExtensions;IIS-ISAPIFilter;IIS-ServerSideIncludes;
IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;
IIS-RequestMonitor;IIS-HttpTracing;IIS-CustomLogging;IIS-ODBCLogging;
IIS-Security;IIS-BasicAuthentication;IIS-WindowsAuthentication;
IIS-DigestAuthentication;IIS-ClientCertificateMappingAuthentication;
IIS-IISCertificateMappingAuthentication;IIS-URLAuthorization;
IIS-RequestFiltering;IIS-IPSecurity;IIS-Performance;IIS-HttpCompressionStatic;
IIS-HttpCompressionDynamic;IIS-WebServerManagementTools;IIS-ManagementConsole;
IIS-ManagementScriptingTools;IIS-ManagementService;IIS-IIS6ManagementCompatibility;
IIS-Metabase;IIS-WMICompatibility;IIS-LegacyScripts;IIS-LegacySnapIn;
IIS-FTPPublishingService;IIS-FTPServer;IIS-FTPManagement;
WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;
WAS-ConfigurationAPI

Now you need to open your web browser and type the following URL for testing

http://localhost

Once IIS is installed, your computer running Windows Vista will be able to function as a Web server. Also, Windows Vista is limited to the number of concurrent inbound connections that it can accept. Home Editions support a maximum of 5 connections. All other editions support a maximum of 10.


Last Updated on Saturday, 13 June 2009 22:46
 
Linux Command Tutorials - Opening a Linux Terminal - Console to Run Linux Commands - Tutorial Help
Linux
Saturday, 30 May 2009 12:46

To run Linux commands, you need to get to the Linux command line prompt.

To get to the Linux command line prompt from a Linux desktop, you open a terminal emulation window.

 

Linux Tips: You can also go to a virtual terminal and run Linux commands. But when you are a new Linux user, a terminal emulation window is easier to work with.

 

 

Linux Terminal Emulation Windows

 

When you open a terminal emulation window, you get a "window" on the desktop. A terminal emulation window can be moved around on the desktop and resized to be made larger or smaller. And you can even have multiple terminal emulation windows open at the same time!

This window shows the Linux command line prompt, at which you can run Linux commands (by typing in commands and pressing Enter). After running a Linux command, this window also shows the output of the command (very important).

 

Linux Tips: Linux commands are the best way to do Linux system administration. Running Linux commands gives you lots of practical, hands-on Linux training.

 

 

Methods of Opening a Linux Terminal Emulation Window (a.k.a. Terminal or Console)

 

There are over 130 Linux distributions (versions)!

The method of opening a terminal emulation window on your Linux desktop is dependant on the Linux distribution (version) you are using and the Linux desktop you are using. Two popular Linux desktops are the GNOME desktop and the KDE desktop.

To open a terminal emulation window, boot your Linux system to a desktop and then:

 

  • look for an icon on the desktop that looks like a computer screen and click on it
  • right-click on the desktop and look for a menu item with the words "Linux terminal", "Linux console", or similar
  • search the menus on the desktop for the words "Linux terminal", "Linux console", or similar, and select the menu item
Linux Concepts and Terms:

 

 

A terminal emulation window is also referred to as a "Linux terminal" or "Linux console".

 

 

Linux commands are sometimes referred to as "Linux terminal commands" and "Linux console commands".

 

 

The Linux command line prompt is sometimes referred to as the CLI for "command line interface".

 

 

Once you have a terminal emulation window open, you will see a Linux command line prompt, which looks similar to this ]$ and the prompt may look different on your system.

 

For example, the prompt may look like this ]# or something else similar.

 

Linux Tips: In our Linux command examples, we are using ]$ to represent the prompt. You don't type in the prompt, you type in the command at the right of the prompt and then press the Enter key to run the command.

 

 

Examples of Opening a Terminal Emulation Window in Several Popular Linux Distributions

 

Ubuntu Linux / Red Hat Linux / Fedora Linux with the GNOME desktop:

 

select the Applications Menu ; select Accessories ; select Terminal.

 

 

Debian Linux with the GNOME desktop: right-click on the desktop and select Terminal.

 

SUSE Linux with the KDE desktop: click on the "Konsole" icon on the desktop (that looks like a computer screen).

What would it be like if you could watch a clearly narrated Linux video tutorial showing several methods of opening a Linux "terminal" / "console" and working at the Linux command line, in several Linux distributions.

To actually see the steps being done and have them clearly described to you in a very pleasant and sometimes even humorous manner.

How useful would it be if you could pause the Linux video and then easily try these methods yourself - well, now you can!

You can watch Free Sample I Learn Linux Video Tutorials at http://www.iLearnLinux.com and get over the steep Linux learning curve.

Sign up for Free I Learn Linux News to receive technical tips, info on new video samples and important updates on Linux.

 

Last Updated on Saturday, 13 June 2009 22:42
 
<< Start < Prev 1 2 3 Next > End >>

Page 1 of 3