2015-09-15 18 views
5

ho un Owin Test Server:impostazione Microsoft OWIN Test Server cookie

using (var testServer = TestServer.Create<TestPipelineConfiguration>()) 
using (var client = new HttpClient(testServer.Handler)) 
{ 
    client 
     .DefaultRequestHeaders 
     .Add("Cookie", $"{AspNetCookies}=HeyThere;"); 

    client.BaseAddress = new Uri("https://testserver/"); 

    var message = client 
        .PostAsync("print", new StringContent(
               jsonProvider.SerialiseObject(new 
               { 
                Url = "https://some/url" 
               }), 
               Encoding.UTF8, "application/json")) 
        .Result; 

    //var message = client.GetAsync("test").Result; 

    message 
     .StatusCode 
     .ShouldBeEquivalentTo(HttpStatusCode.OK); 
} 

voglio impostare altre proprietà su quel biscotto, come HttpOnly, Secure e Domain.

È possibile?

risposta

1

Cookie è un'intestazione con un elenco di elementi chiave-valore. Nel codice sarà simile a questa:

.Add("Cookie", "cookie1=value1;cookie2=value2") 
+0

come fa che rispondere alla domanda: 'Voglio impostare altre proprietà su quel biscotto, come HttpOnly, sicuro e Domain' –

1

proprietà sono parte del valore del cookie, punto e virgola separati, per esempio "Cookie = CookieValue; path = /; HttpOnly"

+0

vorrei poter testare questo subito a conferma, ma da allora mi sono spostato sul progetto che conteneva questo - tuttavia cercherò di farlo appena possibile –

+0

Cosa divertente - Ho appena iniziato il mio progetto che mi aspetto possa testarlo. Quindi ci proveremo ad un certo punto –

Problemi correlati