[Modify] Edit it

This commit is contained in:
sta 2016-07-07 15:12:43 +09:00
parent d006215860
commit e35babea1b

View File

@ -567,25 +567,27 @@ And if you would like to validate the **Origin** header, **Cookies**, or both in
```csharp ```csharp
wssv.AddWebSocketService<Chat> ( wssv.AddWebSocketService<Chat> (
"/Chat", "/Chat",
() => new Chat () { () =>
OriginValidator = val => { new Chat () {
// Check the value of the Origin header, and return true if valid. OriginValidator = val => {
Uri origin; // Check the value of the Origin header, and return true if valid.
return !val.IsNullOrEmpty () && Uri origin;
Uri.TryCreate (val, UriKind.Absolute, out origin) && return !val.IsNullOrEmpty ()
origin.Host == "example.com"; && Uri.TryCreate (val, UriKind.Absolute, out origin)
}, && origin.Host == "example.com";
CookiesValidator = (req, res) => { },
// Check the Cookies in 'req', and set the Cookies to send to the client with 'res' CookiesValidator = (req, res) => {
// if necessary. // Check the cookies in 'req', and set the cookies to send to
foreach (Cookie cookie in req) { // the client with 'res' if necessary.
cookie.Expired = true; foreach (Cookie cookie in req) {
res.Add (cookie); cookie.Expired = true;
} res.Add (cookie);
}
return true; // If valid. return true; // If valid.
}
} }
}); );
``` ```
And also if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketBehavior.Context.Origin` and `WebSocketBehavior.Context.CookieCollection` properties. And also if you would like to get each value of the Origin header and cookies, you should access each of the `WebSocketBehavior.Context.Origin` and `WebSocketBehavior.Context.CookieCollection` properties.