Click here to Skip to main content
15,891,204 members
Articles / Web Development / ASP.NET

Redirector Module

Rate me:
Please Sign up or sign in to vote.
4.68/5 (13 votes)
19 Jan 2010CPOL2 min read 36.1K   35  
Build an ASP.NET HttpModule to have normalized URLs, and avoid duplicate content for a SEO friendly website.
using System;
using System.Collections.Specialized;
using System.Web;

namespace SampleRedirector.Tests.Fakes
{

    public class FakeHttpRequest : HttpRequestBase
    {
        private readonly NameValueCollection _formParams;
        private readonly NameValueCollection _queryStringParams;
        private readonly HttpCookieCollection _cookies;
		private Uri _uri;
		private NameValueCollection _headers = new NameValueCollection();

        public FakeHttpRequest(string url, NameValueCollection formParams, NameValueCollection queryStringParams, HttpCookieCollection cookies)
        {
			_uri = new Uri(url);
            _formParams = formParams;
            _queryStringParams = queryStringParams;
            _cookies = cookies;
        }

        public override NameValueCollection Form
        {
            get
            {
                return _formParams;
            }
        }

        public override NameValueCollection QueryString
        {
            get
            {
                return _queryStringParams;
            }
        }

		public override NameValueCollection Headers
		{
			get
			{
				return _headers;
			}
		}

        public override HttpCookieCollection Cookies
        {
            get
            {
                return _cookies;
            }
        }

		public override Uri Url
		{
			get
			{
				return _uri;
			}
		}

		public void SetUri(string url)
		{
			this._uri = new Uri(url);
		}

		public override string UserHostAddress
		{
			get
			{
				return "127.0.0.1";
			}
		}

		public override string HttpMethod
		{
			get
			{
				return "GET";
			}
		}

    }



}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Spain Spain
Jorge has been working in Software development for more than 10 years. Born in Argentina, he lives in Spain since 2004.

He worked as a consultant for mayor companies including Log, HP and Avanade and holds some technical certifications including MCSD and MCAD.

He is the founder of the asp.net mvc forum open source project Nearforums, the Node.js Cassandra driver and the owner of the news release site prsync.com.

Follow him on Twitter: twitter.com/jorgebg

Contact: jorgebaygondra at gmail

Comments and Discussions