|
140 | 140 | |
141 | 141 | The `value` parameter for a <xref:System.Net.Cookie> must not be a `null` reference (Nothing in Visual Basic). The semicolon (";") and comma (",") characters are reserved and cannot be passed in the `value` parameter unless the string passed in the `value` parameter is enclosed in double quotes. So the following example constructor would succeed, but when you try to add this <xref:System.Net.Cookie> to a <xref:System.Net.CookieContainer> instance with the <xref:System.Net.CookieContainer.Add(System.Net.Cookie)> or <xref:System.Net.CookieContainer.Add(System.Uri,System.Net.Cookie)> methods, the operation will fail and throw an exception: |
142 | 142 | |
143 | | - ``` |
| 143 | + ```csharp |
144 | 144 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "123,456"); |
145 | 145 | cookie.Domain = "https://contoso.com"; |
146 | 146 | new CookieContainer().Add(cookie); |
147 | 147 | ``` |
148 | 148 | |
149 | 149 | However, the following constructor with these special characters escaped will create a <xref:System.Net.Cookie> that can be added to a <xref:System.Net.CookieContainer> instance: |
150 | 150 | |
151 | | - ``` |
| 151 | + ```csharp |
152 | 152 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "\"123,456\""); |
153 | 153 | cookie.Domain = "https://contoso.com"; |
154 | 154 | new CookieContainer().Add(cookie); |
|
222 | 222 | |
223 | 223 | The `value` parameter for a <xref:System.Net.Cookie> must not be a `null` reference (Nothing in Visual Basic). The semicolon (";") and comma (",") characters are reserved and cannot be passed in the `value` parameter unless the string passed in the `value` parameter is enclosed in double quotes. So the following example constructor would succeed, but when you try to add this <xref:System.Net.Cookie> to a <xref:System.Net.CookieContainer> instance with the <xref:System.Net.CookieContainer.Add(System.Net.Cookie)> or <xref:System.Net.CookieContainer.Add(System.Uri,System.Net.Cookie)> methods, the operation will fail and throw an exception: |
224 | 224 | |
225 | | - ``` |
| 225 | + ```csharp |
226 | 226 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "123,456", ""); |
227 | 227 | cookie.Domain = "https://contoso.com"; |
228 | 228 | new CookieContainer().Add(cookie); |
229 | 229 | ``` |
230 | 230 | |
231 | 231 | However, the following constructor with these special characters escaped will create a <xref:System.Net.Cookie> that can be added to a <xref:System.Net.CookieContainer> instance: |
232 | 232 | |
233 | | - ``` |
| 233 | + ```csharp |
234 | 234 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "\"123,456\"", ""); |
235 | 235 | cookie.Domain = "https://contoso.com"; |
236 | 236 | new CookieContainer().Add(cookie); |
|
306 | 306 | |
307 | 307 | The `value` parameter for a <xref:System.Net.Cookie> must not be a `null` reference (Nothing in Visual Basic). The semicolon (";") and comma (",") characters are reserved and cannot be passed in the `value` parameter unless the string passed in the `value` parameter is enclosed in double quotes. So the following example constructor would succeed, but when you try to add this <xref:System.Net.Cookie> to a <xref:System.Net.CookieContainer> instance with the <xref:System.Net.CookieContainer.Add(System.Net.Cookie)> or <xref:System.Net.CookieContainer.Add(System.Uri,System.Net.Cookie)> methods, the operation will fail and throw an exception: |
308 | 308 | |
309 | | - ``` |
| 309 | + ```csharp |
310 | 310 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "123,456", "", "https://contoso.com"); |
311 | 311 | new CookieContainer().Add(cookie); |
312 | 312 | ``` |
313 | 313 | |
314 | 314 | However, the following constructor with these special characters escaped will create a <xref:System.Net.Cookie> that can be added to a <xref:System.Net.CookieContainer> instance: |
315 | 315 | |
316 | | - ``` |
| 316 | + ```csharp |
317 | 317 | System.Net.Cookie cookie = new System.Net.Cookie("contoso", "\"123,456\"", "", "https://contoso.com"); |
318 | 318 | new CookieContainer().Add(cookie); |
319 | 319 | ``` |
|
0 commit comments