using Microsoft.AspNet.Identity;
using Microsoft.Owin.Security.Cookies;
using Owin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Owin;
[assembly: OwinStartup(typeof(ASP.NET_Identity_Owin.Startup))]
namespace ASP.NET_Identity_Owin
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
ConfigureAuth(app);
}
public void ConfigureAuth(IAppBuilder app)
{
// 配置Middleware 組件选项,中间件是为了处理不同的业务例如下面的CookieAuthenticationMiddleware,可以参考他来自定义中间件,可以参考开源的owin--catana代码 //这里是处理使用coocie登陆的中间件,是iappbuilder的扩展方法
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/Account/Login"),
CookieSecure = CookieSecureOption.Never,
});
}
public IAppBuilder UseCookieAuthentication(IAppBuilder app,
CookieAuthenticationOptions options)
{
if (app == null)
{
throw new ArgumentNullException("app");
}
app.Use(typeof(CookieAuthenticationMiddleware), app,
options); //将组件注册进owin管道,--CookieAuthenticationMiddleware--组件是操作加密cookie的app.UseStageMarker(PipelineStage.Authenticate); // 然后结合例如IIS(owin的HOST)的某个阶段执行该组件,这里是认证阶段,还有七八种其他的例如post数据阶段等 return app; }
return app;
}
}
}
确定下项目中是否引用了Microsoft.Owin.Host.SystemWeb。
如果发布的项目,确认下生成的bin文件夹是否有Microsoft.Owin.Host.SystemWeb。