Skip to content

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

Updated: at 02:12 PM


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, <span class="kwrd">false</span>);



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!

Check out the ORM (Object Relational Mapper) PRISMA. The database access method I use in all my projects