C# Owin Startup 不会触发的解决办法

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值