2016-10-09 1 views
2

私はAspNetRolesでドロップダウンリストを作成したいと思います。アプリケーションの読み込み中に次のエラーが発生しました。 - OwinStartupAttribute.FriendlyNameの値

Idnetityコンファレンス:

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>())); 
    } 
} 

私はこのコードを使用します。

STARTUP:

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); 
     } 
    } 
} 

。 ウェブ設定:

<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> 

しかし、私は、プロジェクトを実行したときに私は、このエラーを示しています。

アプリの読み込み中に次のエラーが発生しました。 - OwinStartupAttribute.FriendlyName値 'が' Identity_Work、Version = 1.0.0.0、Culture = neutral、PublicKeyToken = null 'の' Identity_Work.IdentityConfig 'と一致しません。 - 指定されたタイプまたはメソッド 'Identity_Work.IdentityConfig'が見つかりませんでした。アセンブリを指定してみてください。 OWINの起動検出を無効にするには、web.configに「false」の値を持つappSetting owin:AutomaticAppStartupを追加します。 OWINの起動アセンブリ、クラス、またはメソッドを指定するには、webSetで完全修飾スタートアップクラスまたは構成メソッド名を使用してappSetting owin:AppStartupを追加します。

。どうしたの ?

編集

enter image description here

+0

は、完全な起動ファイルを表示します。 webconfig – Nkosi

+0

更新に関する質問の関連する設定 – Kianoush

答えて

4

エラーメッセージが

を説明同様OwinStartupAttribute.FriendlyName値は 'Identity_Work.IdentityConfig' 与えられた値と一致していない ''

Fエラーメッセージの指示に従ってください

「Identity_Work.IdentityConfig」という型が見つかりませんでした。 アセンブリを指定してみてください。 OWINの起動ディスカバリを無効にするには、 web.configに appSetting owin:AutomaticAppStartupを値 "false"で追加します。 OWINの起動アセンブリ、クラス、または メソッドを指定するには、web.configに完全修飾の 起動クラスまたは構成メソッド名を指定してappSetting owin:AppStartupを追加します。

まず、それが存在し、参照されていない場合、それは、あなたがweb.configファイルでowin:AppStartupを削除する必要がない場合は、それがクラス

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

への正しい参照を持っているかどうかを確認するためにStartup.csをチェックする必要があります正しいクラス

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

そうしないと、owinが

を使用できるようにweb.configファイルを更新することができます
+0

私は何をすべきですか? – Kianoush

+0

それは私にこのエラーを表示します。 'HTTP Error 401.0 - Unauthorized' – Kianoush

+0

URLは?マップされたアクションに '[AllowAnonymous]'属性を入れてください。 – Nkosi

0

私は完全なルートを指定するだけで、私にとってはうまくいきます!

Project name: Users.Web 
Folders: App_Start 
Class name: IdentityConfig 

<add key="owin:AppStartup" value="Users.Web.App_Start.IdentityConfig" /> 

enter image description here

関連する問題