none
RegEx to support inspecting cookies in IIS UrlRewrite RRS feed

  • Question

  • Hi,

    Since my question is specifically about RegEx usage, I thought I would try in here. Scenario is that I need to ensure that a specific cookie is delivered in IIS UrlRewrite. The logic in UrlRewrite lets me negate a pattern match but lets say that I want to have a match on a specific cookie.

    The input is a string that consist of key value pairs like this:

    "ASP.NET_SessionId=uphq4nuxliet0wy2glvpsi;MyCookie=MySpecificValue"

    So the key/values are separeted with a semmicolon ";". The task is to ensure that the string contains the cookie "MyCookie" with the value "MySpecificValue".

    The easy way would be to just use the pattern "*MyCookie=MySpecificValue*". But that would also produce a match on "NotMyCookie=MySpecificValueItIsNot" which I obviously do not want.

    What could the correct RegEx look like?

    /Werner

    Thursday, February 4, 2016 9:32 AM

Answers

  • Hi

    you could do like that :

    Regex.IsMatch("ASP.NET_SessionId=uphq4nuxliet0wy2glvpsi;MyCookie=MySpecificValue", @"((^MyCookie)|;MyCookie)=((MySpecificValue$)|MySpecificValue;)");

    Regards

    Cedric

    • Marked as answer by Werner Clausen Thursday, February 4, 2016 2:32 PM
    Thursday, February 4, 2016 10:25 AM