加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 尝试加载应用程序时发生以下错误. – OwinStartupAttribut

发布时间:2020-12-15 23:35:40 所属栏目:百科 来源:网络整理
导读:我想用AspNetRoles创建下拉列表.我用这个代码: Idnetity Conf: public class ApplicationRoleManager : RoleManagerIdentityRole{ public ApplicationRoleManager(IRoleStoreIdentityRole,string roleStore) : base(roleStore) { } public static Applicat
我想用AspNetRoles创建下拉列表.我用这个代码:

Idnetity Conf:

public class ApplicationRoleManager : RoleManager<IdentityRole>
{
    public ApplicationRoleManager(IRoleStore<IdentityRole,string> roleStore)
        : base(roleStore)
    {
    }

    public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options,IOwinContext context)
    {
        return new ApplicationRoleManager(new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>()));
    }
}

.

启动:

using System;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.Owin;
using Microsoft.Owin.Security.Cookies;
using Microsoft.Owin.Security.Google;
using Owin;
using Identity_Work.Models;

namespace Identity_Work
{
    public partial class Startup
    {
        public void ConfigureAuth(IAppBuilder app)
        {
            app.CreatePerOwinContext(ApplicationDbContext.Create);
            app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
            app.CreatePerOwinContext<ApplicationRoleManager>(ApplicationRoleManager.Create);
            app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,LoginPath = new PathString("/Account/Login"),Provider = new CookieAuthenticationProvider
                {  
                    OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager,ApplicationUser>(
                        validateInterval: TimeSpan.FromMinutes(30),regenerateIdentity: (manager,user) => user.GenerateUserIdentityAsync(manager))
                }
            });
            app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);            app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie,TimeSpan.FromMinutes(5));    app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);
        }
    }
}

.
Web配置:

<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AppStartup" value="Identity_Work.IdentityConfig" />

控制器:

[AllowAnonymous]
public ActionResult Register()
{
    ViewBag.name = new SelectList(db.Roles,"RoleID","RoleName");

    return View();
}

查看:

<div class="form-group">
    <label>??? ?????</label>
    <div class="col-md-10">
        @Html.DropDownList("name","--Select Name--")
    </div>
</div>

但是当我运行项目时显示这个错误:

The following errors occurred while attempting to load the app.
– The OwinStartupAttribute.FriendlyName value ” does not match the given value ‘Identity_Work.IdentityConfig’ in Assembly ‘Identity_Work,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null’.
– The given type or method ‘Identity_Work.IdentityConfig’ was not found. Try specifying the Assembly.
To disable OWIN startup discovery,add the appSetting owin:AutomaticAppStartup with a value of “false” in your web.config.
To specify the OWIN startup Assembly,Class,or Method,add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

.有什么问题 ?

编辑

enter image description here

解决方法

像错误消息解释一样

The OwinStartupAttribute.FriendlyName value ” does not match the
given value ‘Identity_Work.IdentityConfig’

按照错误消息的说明进行操作

The given type or method ‘Identity_Work.IdentityConfig’ was not found.
Try specifying the Assembly. To disable OWIN startup discovery,add
the appSetting owin:AutomaticAppStartup with a value of “false” in
your web.config. To specify the OWIN startup Assembly,or
Method,add the appSetting owin:AppStartup with the fully qualified
startup class or configuration method name in your web.config.

首先您应该检查Startup.cs以查看它是否具有对该类的正确引用

[assembly: OwinStartup(typeof(Identity_Work.Startup))]

如果是,那么你需要删除web.config中的owin:AppStartup(如果它存在)并且没有引用正确的类

<add key="owin:AutomaticAppStartup" value="true" />

否则,您可以更新web.config以让owin使用

<add key="owin:AutomaticAppStartup" value="false" />
<add key="owin:AppStartup" value="Identity_Work.Startup" />

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读