Custom ServerVariable IIS

656 Views Asked by At

i am trying to create a custom servervariable with url rewrite. Url Rewrite for IIS generates the following config entry

    <rewrite>
        <rules>
          <rule name="CName to URL - Rewrite" stopProcessing="true">
              <match url=".*" />
              <conditions>
                    <add input="{HTTP_HOST}" pattern="^(?!www)(.*)\.localfurnco\.de" />
              </conditions>
              <action type="Rewrite" url="?" appendQueryString="false" />
                <serverVariables>
                    <set name="HTTP_MANUFACTURER" value="{C:1}" />
                </serverVariables>
          </rule>   
        </rules>
    </rewrite>

But when iterating through the servervariables i can't find HTTP_MANUFACTURER. The url rewrite seems to work but i can't get the Variable.

I am trying to call the address: test.localfurnco.de/subdir/webservice.asmx?wsdl.

C:1 should in this case be: "test".

I would be grateful for any suggestion and thanks in advance

1

There are 1 best solutions below

0
On

After trying some hours i figured it out myself. Here is the resulting rule.

            <rule name="CName to URL - Rewrite" stopProcessing="false">
                <match url=".*" negate="false" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="true">
                    <add input="{SERVER_NAME}" pattern="^(?!www)(.*)\.localfurnco\.de" />
                </conditions>
                <action type="Rewrite" url="?CustomValue={C:1}" logRewrittenUrl="true" />
                <serverVariables>
                    <set name="HTTP_MANUFACTURER" value="{C:1}" />
                </serverVariables>
            </rule>   

With this rule it is possible to access the ServerVariable "HTTP_MANUFACTURER" from C#:

   string variable= httpContext.Current.Request.ServerVariables.Get("HTTP_MANUFACTURER");

A Different option a friend shared with me is this:

   string value= HttpContext.Current.Request.Params.Get("CustomValue");

As you can see i rewrite the url and set a parameter which i assign the, by the pattern, filtered value.

I hope this helps somebody else.