0

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 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.