【发布时间】:2016-12-09 12:13:02
【问题描述】:
在我提出问题之前,我已经浏览了以下帖子:
- Can't get the OWIN Startup class to run in IIS Express after renaming ASP.NET project file 以及问题中提到的所有帖子。
- OWIN Startup Detection
- OwinStartupAttribute required in web.config to correct Server Error #884
- OWIN Startup class not detected
这是我项目的文件夹布局:
Startup.cs
using System;
using Microsoft.Owin;
using Owin;
[assembly: OwinStartup(typeof(Bootstrapper.Startup))]
namespace Bootstrapper
{
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.Run(async context =>
{
await context.Response.WriteAsync(GetTime() + " My First OWIN App");
});
}
string GetTime()
{
return DateTime.Now.Millisecond.ToString();
}
}
}
Web.config
<appSettings>
<add key="owin:AutomaticAppStartup" value="true" />
<add key="owin:appStartup" value="Bootstrapper.Startup" />
<add key="webpages:Version" value="2.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
我在Bootstrapper 项目中有以下参考:
- Microsoft.Owin
- Microsoft.Owin.Host.SystemWeb
- 欧文
- 系统
- System.Core
更新:
忘记添加错误信息:
现在,
- 为什么它不起作用?
- 在一个非常基本的项目中添加和使用
Owin Startup类的分步过程是什么(例如访问Home/Index)? -
Owin Startup类中的配置方法如何以及何时 调用/执行?
更新: 2016 年 12 月 10 日
检查Project-Folder-Layout。在Bootstrapper 项目中,我有以下文件:
IocConfig.cs
[assembly: PreApplicationStartMethod(typeof(IocConfig), "RegisterDependencies")]
namespace Bootstrapper
{
public class IocConfig
{
public static void RegisterDependencies()
{
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource());
builder.RegisterModule<AutofacWebTypesModule>();
builder.RegisterType(typeof(MovieService)).As(typeof(IMovieService)).InstancePerRequest();
builder.RegisterType(typeof(MovieRepository)).As(typeof(IMovieRepository)).InstancePerRequest();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
}
}
}
现在我想在OWIN Startup 类中执行IocConfig.RegisterDependencies()。我在顶部的Startup 中做using Bootstrapper,但是它不起作用。我的意思是我无法在Startup 中引用IocConfig。如何解决?
【问题讨论】:
标签: c# asp.net-mvc-4 owin owin-middleware