How To Convert From Request With Parameter to No Parameter in ASP.NET (Server.Transfer)


The problem is that I’m trying to keep track of the exact URL a person selects including the request parameter.  That is, I have a URLs that can be played as follows:


I’ve actually got 7 videos that I want people to be able to play.  The problem is that my web statistics tracker is going to count all videos as coming from TestPage.html and I will not be able to tell which video is getting how much traffic.  What I’d really like is have unique landing pages for each one that I can put links to on my blog, and then have those tracked separately.

So, here is what I would like:

Then, in my web stats, I will see the following


To achieve this, the solution is to add a “WildCardMapper” to IIS7 so that all requests, including those without extensions go through the pipeline.  Then, the requests can be trapped in either a module, or simply in the global.asax.cs which is how I did it for simplicity.

To do this, the following code needs to be put in the web.config modules section:

        <modules runAllManagedModulesForAllRequests="true"    >

Then, in the global.asax.cs file, you add the following code:

  protected void Application_BeginRequest(object sender, EventArgs e)
            var incomingUrlFromRequest = HttpContext.Current.Request.Url;
            if (incomingUrlFromRequest != null && incomingUrlFromRequest.Segments.Count() == 2 &&
                string newPath = //Context.Request.MapPath("~") +
                    String.Format("TestPage.html?src={0}", incomingUrlFromRequest.Segments[1]).Replace("_wmv", ".wmv");

                Server.Transfer(newPath, false);



Now, the translation happens exactly as you would expect.  That is, when you enter the URL: invisibly, you are taken to because Server.Transfer is used.  The browser does not even know the transfer took place, and the URL stays the same in the top of the users browser.


Hope this helps!

About Peter Kellner

Peter is a software professional specializing in mobile and web technologies. He has also been a Microsoft MVP since 2007. In addition, he's a multi-course video author at Pluralsight. To read more about Peter Kellner and his experience click here. For information about how Peter Kellner might be able to help you with your project click here.

Follow me:


  1. Hi VVVlad,
    Thanks for he suggestion. I am a native english speaker, I know the rules, but somehow I don’t see the errors. My brain sees it correctly even though it’s wrong. feel free to jump in with any other corrections and I’ll happily make them

  2. I’m not naively English speaker, but I couldn’t read the article and ignore the “video’s”.
    video’s == video is
    videos == plural of video

    sorry for not related comment.

  3. I would recommend using instead of coding it by hand. It’s a free URL rewriter. You can have all of your URL’s setup in an XML file. I think all you need to do is add the config section, and the HTTP Module to the web.config.

    I have even used it in conjunction with a CMS and it worked pretty well. It was a little harder since the CMS had it’s own rewriting going on, but I just had to find the right place to call the URL Rewriter method (instead of using the module).


Get every new post delivered to your Inbox

Join other followers: