Quantcast
Channel: All Forums
Viewing all articles
Browse latest Browse all 27852

Exposing HttpRequest.Browser properties to rewrite rules

$
0
0

I'm looking for a way to redirect requests based on device types like phone, tablet, desktop, tv, etc.

So I wrote a managed (C#) IHttpModule for device detection and extended the HttpBrowserCapabilities with an additional "DeviceType" property. The module also adds this property to the request headers / server variables (like HTTP_DEVICE_TYPE: "tablet"). Check, no problem there.

Next, I planned to use this server variable in IIS Rewrite 2.0 rules, but ran into three major problems:

1. IIS Rewrite 2.0 exposes server variables, but other request information (i.e. the HttpRequest.Browser properties) are unavailable.Question 1: Is it possible to use HttpRequest.Browser properties in rewrite rules (something like rule / conditions / add input="{Browser:DeviceType}")?

2. The IIS Rewrite Module executes BEFORE my module, so my additional HTTP_DEVICE_TYPE server variable is not available for rewriting.Question 2: Is there any way to assure that my module executes BEFORE the IIS rewrite module (both are assigned to the first HttpApplication.BeginRequest event).

3. As a work-around, I tried to change my IHttpModule into a IIS Rewrite 2.0 custom provider. But I found no way to access the current request (i.e. a HttpRequest instance) from a custom rewrite provider. Question 3: Is there any way to do this?

I have tried other solutions mentioned in this forum as well, like rewrite conditions based on the HTTP_USER_AGENT server variable, but above a certain level of accuracy, these rules become increasingly complex and performance consuming.

Thanx

Peroks


Viewing all articles
Browse latest Browse all 27852

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>