Question

I'm trying to make a IIS URL rewrite rule that appends an URL parameter to the URL. The url parameter is hssc. So, any url that is processed through the server, needs that parameter. Keeping in mind that some urls will have their own params already, and other urls won't, and root urls, etc, sometimes it will need to add ?hssc=1 or &hssc= - so, if I have a URL that is as such:

I also want it that the URL should not be hidden (as in a backend rewrite behind the scenes). I need the URL to appear in the URL, so when users copy the URL, or bookmark it, the parameter is there.

I've set the condition to match it \&hssc|\?hssc - now I just need a way to write the URL, so it appears and keeps the part of the original URL that is already there.

Était-ce utile?

La solution

Figured this out - the rule will be set up as such:

<rewrite>
            <rules>
                <rule name="sigh" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" negate="false" />
                    <action type="Redirect" url="{PATH_INFO}?hssc=1" />
                    <conditions>
                        <add input="{QUERY_STRING}" pattern="^hssc=|\?hssc=|\&amp;hssc=" negate="true" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>

Autres conseils

 

just as a hint to maintain QS through the code:

public static string GetQS()
{
  var sb = new System.Text.StringBuilder();

  System.Collections.Specialized.NameValueCollection Qs = HttpContext.Current.Request.QueryString;

  var lst = new List<string>(Qs.AllKeys);

  foreach (string s in lst)
  {
    if (s == "MyOwnQSKey")
      sb.Append(s + "=" + "MyValue" + "&");
    else
      sb.Append(s + "=" + Qs[s] + "&");
  }

  if (!lst.Contains("MyOwnQSKey"))
    sb.Append("MyOwnQSKey=MyValue&");

  if (sb.ToString().EndsWith("&"))
    sb.Remove(sb.Length - 1, 1);

  return "?" + sb;
}

i just copied this from one of my projects similar to yours in Url-Rewrite and QS

hope this help

 

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top