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:
http://video.peterkellner.net/TestPage.html?src=P1_Intro.wmv
http://video.peterkellner.net/TestPage.html?src=P2_BasicRIANoTooling.wmv
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:
http://video.peterkellner.net/P2_BasicRIANoTooling_wmv
http://video.peterkellner.net/P2_BasicRIANoTooling_wmv
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 asp.net pipeline. Then, the requests can be trapped in either a asp.net 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:
<system.webServer>
<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 && incomingUrlFromRequest.Segments[1].EndsWith("_wmv")) { 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: http://video.peterkellner.net/P2_BasicRIANoTooling_wmv invisibly, you are taken to http://video.peterkellner.net/TestPage.html?src=P1_Intro.wmv 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!









January 26th, 2010 at 6:37 am
I would recommend using http://urlrewriter.net/ 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).
January 28th, 2010 at 1:38 pm
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.
January 28th, 2010 at 3:11 pm
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