OWIN是Open Web Server Interface for .NET的首字母縮寫,他的定義如下:
OWIN在.NET Web Servers與Web Application之間定義了一套標準接口,OWIN的目標是用於解耦Web Server和Web Application。基於此標準,鼓勵開發者開發簡單、靈活的模組,從而推進.NET Web Development開源生態系統的發展。
OWIN的作用
- ASP.NET的核心System.Web,而System.Web緊耦合IIS
- System.Web是.NET Framework重要組成,已有15年以上歷史,沉重、冗餘,性能差,難於測試,約2.5M
- System.Web要更新和發布新功能必須等待.NET Framework發布
- .但NET Framework是Windows的基礎,往往不會隨意更新。
- IIS往往和作業系統(Windows Server)綁定在一起,這意味著對於一些新功能如WebSocket Protocol,我們不得不等待作業系統Windows Sever 2012、Windows 8的發布(IIS 8.0)。
- 為了使用WebSocket這類新特性,他僅被IIS 8.0支持,如下所示:
- IIS作為經典的Web Server必須安裝在Windows系統中,Windows Server需要授權使用。
OWIN的規範
Required | Key Name | Value Description |
Yes | "owin.RequestBody" | AStreamwith the request body, if any.Stream.NullMAY be used as a placeholder if there is no request body. SeeRequest Body. |
Yes | "owin.RequestHeaders" | AnIDictionary<string, string[]>of request headers. SeeHeaders. |
Yes | "owin.RequestMethod" | Astringcontaining the HTTP request method of the request (e.g.,"GET","POST"). |
Yes | "owin.RequestPath" | Astringcontaining the request path. The path MUST be relative to the "root" of the application delegate; seePaths. |
Yes | "owin.RequestPathBase" | Astringcontaining the portion of the request path corresponding to the "root" of the application delegate; seePaths. |
Yes | "owin.RequestProtocol" | Astringcontaining the protocol name and version (e.g."HTTP/1.0"or"HTTP/1.1"). |
Yes | "owin.RequestQueryString" | Astringcontaining the query string component of the HTTP request URI, without the leading “?” (e.g.,"foo=bar&baz=quux"). The value may be an empty string. |
Yes | "owin.RequestScheme" | Astringcontaining the URI scheme used for the request (e.g.,"http","https"); seeURI Scheme. |
Required | Key Name | Value Description |
Yes | "owin.ResponseBody" | AStreamused to write out the response body, if any. SeeResponse Body. |
Yes | "owin.ResponseHeaders" | An IDictionary<string, string[]> of response headers. SeeHeaders. |
No | "owin.ResponseStatusCode" | An optionalintcontaining the HTTP response status code as defined inRFC 2616section 6.1.1. The default is 200. |
No | "owin.ResponseReasonPhrase" | An optionalstringcontaining the reason phrase associated the given status code. If none is provided then the server SHOULD provide a default as described inRFC 2616section 6.1.1 |
No | "owin.ResponseProtocol" | An optionalstringcontaining the protocol name and version (e.g."HTTP/1.0"or"HTTP/1.1"). If none is provided then the“owin.RequestProtocol”key’s value is the default. |
Required | Key Name | Value Description |
Yes | "owin.CallCancelled" | ACancellationTokenindicating if the request has been cancelled/aborted. SeeRequest Lifetime. |
Yes | "owin.Version" | Thestring"1.0"indicating OWIN version. SeeVersioning. |