Događaj
Power BI DataViz Svetsko prvenstvo
14. feb 16 - 31. mar 16
Sa 4 šanse za ulazak, možete osvojiti konferencijski paket i stići do LIVE Grand Finale u Las Vegasu
Saznajte višeOvaj pregledač više nije podržan.
Nadogradite na Microsoft Edge biste iskoristili najnovije funkcije, bezbednosne ispravke i tehničku podršku.
By Steve Smith and Rick Anderson
ASP.NET Core:
Microsoft.Owin.*
(Katana) libraries.OWIN allows web apps to be decoupled from web servers. It defines a standard way for middleware to be used in a pipeline to handle requests and associated responses. ASP.NET Core applications and middleware can interoperate with OWIN-based applications, servers, and middleware.
OWIN provides a decoupling layer that allows two frameworks with disparate object models to be used together. The Microsoft.AspNetCore.Owin
package provides two adapter implementations:
This allows ASP.NET Core to be hosted on top of an OWIN compatible server/host or for other OWIN compatible components to be run on top of ASP.NET Core.
Napomena
Using these adapters comes with a performance cost. Apps using only ASP.NET Core components shouldn't use the Microsoft.AspNetCore.Owin
package or adapters.
View or download sample code (how to download)
ASP.NET Core's OWIN support is deployed as part of the Microsoft.AspNetCore.Owin
package. You can import OWIN support into your project by installing this package.
OWIN middleware conforms to the OWIN specification, which requires a Func<IDictionary<string, object>, Task>
interface, and specific keys be set (such as owin.ResponseBody
). The following simple OWIN middleware displays "Hello World":
public Task OwinHello(IDictionary<string, object> environment)
{
string responseText = "Hello World via OWIN";
byte[] responseBytes = Encoding.UTF8.GetBytes(responseText);
// OWIN Environment Keys: https://owin.org/spec/spec/owin-1.0.0.html
var responseStream = (Stream)environment["owin.ResponseBody"];
var responseHeaders = (IDictionary<string, string[]>)environment["owin.ResponseHeaders"];
responseHeaders["Content-Length"] = new string[] { responseBytes.Length.ToString(CultureInfo.InvariantCulture) };
responseHeaders["Content-Type"] = new string[] { "text/plain" };
return responseStream.WriteAsync(responseBytes, 0, responseBytes.Length);
}
The sample signature returns a Task
and accepts an IDictionary<string, object>
as required by OWIN.
The following code shows how to add the OwinHello
middleware (shown above) to the ASP.NET Core pipeline with the UseOwin
extension method.
public void Configure(IApplicationBuilder app)
{
app.UseOwin(pipeline =>
{
pipeline(next => OwinHello);
});
}
You can configure other actions to take place within the OWIN pipeline.
Napomena
Response headers should only be modified prior to the first write to the response stream.
Napomena
Multiple calls to UseOwin
is discouraged for performance reasons. OWIN components will operate best if grouped together.
app.UseOwin(pipeline =>
{
pipeline(next =>
{
return async environment =>
{
// Do something before.
await next(environment);
// Do something after.
};
});
});
You can construct an OWIN environment using the HttpContext
.
var environment = new OwinEnvironment(HttpContext);
var features = new OwinFeatureCollection(environment);
OWIN depends on an IDictionary<string,object>
object to communicate information throughout an HTTP Request/Response exchange. ASP.NET Core implements the keys listed below. See the primary specification, extensions, and OWIN Key Guidelines and Common Keys.
Key | Value (type) | Description |
---|---|---|
owin.RequestScheme | String |
|
owin.RequestMethod | String |
|
owin.RequestPathBase | String |
|
owin.RequestPath | String |
|
owin.RequestQueryString | String |
|
owin.RequestProtocol | String |
|
owin.RequestHeaders | IDictionary<string,string[]> |
|
owin.RequestBody | Stream |
Key | Value (type) | Description |
---|---|---|
owin.RequestId | String |
Optional |
Key | Value (type) | Description |
---|---|---|
owin.ResponseStatusCode | int |
Optional |
owin.ResponseReasonPhrase | String |
Optional |
owin.ResponseHeaders | IDictionary<string,string[]> |
|
owin.ResponseBody | Stream |
Key | Value (type) | Description |
---|---|---|
owin.CallCancelled | CancellationToken |
|
owin.Version | String |
Key | Value (type) | Description |
---|---|---|
ssl.ClientCertificate | X509Certificate |
|
ssl.LoadClientCertAsync | Func<Task> |
|
server.RemoteIpAddress | String |
|
server.RemotePort | String |
|
server.LocalIpAddress | String |
|
server.LocalPort | String |
|
server.OnSendingHeaders | Action<Action<object>,object> |
Key | Value (type) | Description |
---|---|---|
sendfile.SendAsync | See delegate signature | Per Request |
Key | Value (type) | Description |
---|---|---|
opaque.Version | String |
|
opaque.Upgrade | OpaqueUpgrade |
See delegate signature |
opaque.Stream | Stream |
|
opaque.CallCancelled | CancellationToken |
Key | Value (type) | Description |
---|---|---|
websocket.Version | String |
|
websocket.Accept | WebSocketAccept |
See delegate signature |
websocket.AcceptAlt | Non-spec | |
websocket.SubProtocol | String |
See RFC6455 Section 4.2.2 Step 5.5 |
websocket.SendAsync | WebSocketSendAsync |
See delegate signature |
websocket.ReceiveAsync | WebSocketReceiveAsync |
See delegate signature |
websocket.CloseAsync | WebSocketCloseAsync |
See delegate signature |
websocket.CallCancelled | CancellationToken |
|
websocket.ClientCloseStatus | int |
Optional |
websocket.ClientCloseDescription | String |
Optional |
Povratne informacije za ASP.NET Core
ASP.NET Core je projekat otvorenog koda. Izaberite vezu da biste pružili povratne informacije:
Događaj
Power BI DataViz Svetsko prvenstvo
14. feb 16 - 31. mar 16
Sa 4 šanse za ulazak, možete osvojiti konferencijski paket i stići do LIVE Grand Finale u Las Vegasu
Saznajte višeObuka
Modul
Customize ASP.NET Core behavior with middleware - Training
Understand and implement middleware in an ASP.NET Core app. Use included middleware like HTTP logging and authentication. Create custom middleware to handle requests and responses.
Dokumentacija
This tutorial shows how to configure which OWIN startup class is loaded. For more information on OWIN, see An Overview of Project Katana. This tutorial was...
OWIN Middleware in the IIS integrated pipeline
This article shows how to run OWIN middleware Components (OMCs) in the IIS integrated pipeline, and how to set the pipeline event an OMC runs on. You should...
Use OWIN to Self-Host ASP.NET Web API - ASP.NET 4.x
Tutorial with code showing how to host ASP.NET Web API in a console application.