【发布时间】:2018-02-02 16:29:25
【问题描述】:
我有一个使用 CORS 和 Autofac 的 owin 设置。 Autofac 文档说“首先注册 Autofac 中间件。”,很多人说 app.UseCors 应该是第一件事。
我还有一个异常处理中间件,很多人也说它应该是第一件事,这样“其他中间件(在堆栈跟踪中)将向上传播并被该中间件的 try/catch 块捕获。”,以及这很有意义,因为实现看起来像:
try
{
await Next.Invoke(context);
}
catch...
哪一个应该是第一个? 这 3 个中间件组件的正确顺序是什么
我当前的启动配置如下所示:
public void Configuration(IAppBuilder app) {
// Add WebApi CORS handling to the OWIN pipeline
app.UseCors(CorsOptions.AllowAll);
// Create and register Owin HttpConfig instance
var config = new HttpConfiguration
{
IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always // Enable error details in http responses
};
// Register the Autofac middleware FIRST. This also adds Autofac-injected middleware
// registered with the container.
var container = AutofacConfig.ConfigureContainer(config);
app.UseAutofacMiddleware(container);
app.UseAutofacWebApi(config);
app.UseNLog();
// Handle exceptions from OWIN middleware components globally
app.UseExceptionHandling();
app.UseOAuth(config);
//... quite a bit more stuff after
【问题讨论】:
标签: owin autofac startup owin-middleware