ホストプロバイダーは、データベースへのリモートアクセスを許可していません。Configuration.csのシードメソッドのオーバーライドが機能しない

デニス・ディアロ

私のホスティングプロバイダー(www.binero.se)は、データベースへのリモートアクセスを許可していないため、Webアプリの展開が困難です。MVCアプリをサーバーに公開する必要があり、それが機能することを願っています。デプロイするアプリは、Visual Studio2013で新しいMVCアプリを作成するときに取得する標準アプリです。EF6とMVC5を使用しているEnable-Migrations-EnableAutomaticMigrationsを使用してアプリに移行を追加しました。アクセスしようとしているサーバーはMSSQLServerです。

AspNet Identityのテーブルを作成し、最終的には他のいくつかのテーブルを作成する必要がありますが、Configuration.csのInitial Migration andSeedメソッドが呼び出されていません。私が理解しているように、アクセス時にデータベースを呼び出して作成し、データを入力する必要があります。そのため、移行を使用しています。エラー報告を改善するためにElmahロギングを追加しようとしましたが、ローカルホストでしか機能しないようです。例外がスローされた後に/elmah.axdにアクセスしようとすると、サーバーはリソースが存在しないことを通知するだけです。Wtf?Elmahがルーティングを担当すると思いました。

面白いことに、MigrationsとSeedメソッドを使用しない場合 ASPはデータベーステーブルを作成しますつまり、標準テンプレートMVCアプリを公開して登録しようとすると、データベースにテーブルが作成され、新しく登録されたユーザーデータが挿入されます。これは、接続文字列に問題がないことを示しています。では、IdentityDbContextがテーブルを作成してデータを挿入できるのはどうしてですか。しかし、ApplicationContext(IdentityDbContextから派生)を使用してConfiguration.csを介してシードしようとすると、機能しません。テーブルは作成されず、データは挿入されません。なぜ?!私はこれを理解しようとして24時間髪を引き裂いてきました。私を助けてください。

とにかく、アカウント/ログインに移動して資格情報を入力すると、次のように表示されます。

移行はコンテキスト「ApplicationDbContext」に対して有効になっていますが、データベースが存在しないか、マップされたテーブルが含まれていません。たとえば、パッケージマネージャーコンソールから「Update-Database」コマンドを実行して、データベースとそのテーブルを停止します。

私はそれが存在しないことを知っています!そのため、Initial_CreateMigrationを実行する必要があります。

また、内部サーバーエラー(500)を確認して取得しましたが、何が起こるかをデバッグできません。

Configuration.cs

 internal sealed class Configuration : DbMigrationsConfiguration<UsersSeedMigrationCSharp.Models.ApplicationDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;
    }

    protected override void Seed(UsersSeedMigrationCSharp.Models.ApplicationDbContext context)
    {
        var UserManager = new UserManager<ApplicationUser>(new
                    UserStore<ApplicationUser>(new ApplicationDbContext()));
        var RoleManager = new RoleManager<IdentityRole>(new
                            RoleStore<IdentityRole>(new ApplicationDbContext()));
        string password = "password";
        //Create Role Admin if it does not exist
        if (!RoleManager.RoleExists("admin"))
        {
            RoleManager.Create(new IdentityRole("admin"));
        }


        var user = new ApplicationUser { UserName = "admin" };
        var addresult = UserManager.Create(user, password);
        //Add User Admin to Role Admin
        if (addresult.Succeeded)
        {
            var result = UserManager.AddToRole(user.Id, "admin");
        }

Web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup></configSections>
<connectionStrings>
<!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsersSeedMigrationCSharp-20131217074025.mdf;Initial Catalog=aspnet-UsersSeedMigrationCSharp-20131217074025;Integrated Security=True" providerName="System.Data.SqlClient" />-->
<add name="DefaultConnection" connectionString="Data Source=XXX;Initial Catalog=XXXXX;Persist Security Info=True;User ID=XXX;Password=XXX" providerName="System.Data.SqlClient" />
</connectionStrings>
<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" />
</appSettings>
<system.web>
<authentication mode="None" />
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="Off"/>
<httpRuntime targetFramework="4.5" />
<httpModules>
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
<add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" />
<add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" />
</httpModules></system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
<add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /><add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /><add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /></modules>
<validation validateIntegratedModeConfiguration="false" /></system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<elmah>
<!--
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
more information on remote access and securing ELMAH.
-->
<security allowRemoteAccess="true" />
</elmah><location path="elmah.axd" inheritInChildApplications="false">
<system.web>
<httpHandlers>
<add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
</httpHandlers>
<!-- 
See http://code.google.com/p/elmah/wiki/SecuringErrorLogPages for 
more information on using ASP.NET authorization securing ELMAH.

<authorization>
<allow roles="admin" />
<deny users="*" />  
</authorization>
-->  
</system.web>
<system.webServer>
<handlers>
<add name="ELMAH" verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" />
</handlers>
</system.webServer>
</location></configuration>
J.オルソン

これは古いトピックですが、私は何かを説明しようとします。

Bineroは現在、移行の完全な拡張をサポートしていません。「デバッグ」モードでのコードの最初の移行により、データベースが消去され、モデルを参照として新しいデータベースが作成されます。データベースを消去および作成できないため、Bineroはこれを許可しません(これはbineroコントロールパネル内で実行されます)。代わりに、すべてのテーブルを削除し、データベースへの現在の接続に新しいテーブルをシードするようにエンティティフレームワークに指示する必要があります。

これは、その方法を説明するリンクです:http//www.binero.se/support/faq/webbdatabas/aspnet/hur-anvander-jag-aspnet-mvc3-ef-41-codefirst

そして他の問題、Bineroはバージョン4.1より新しいMVC5とEntityFrameworkをサポートしていません(私が彼らのウェブサイトhttp://www.binero.se/support/faq/webbdatabas/aspnet/vilka-komponenter-harで読んだものから)-ni-installerade-i-er-windowsmiljo

更新:タフなBineroでさえ、MVC5またはEF 6をサポートしているとは言わないでください。ドメインを.NetFramework 4.5.1(または4.5どちらが有効な代替手段か覚えていません)としてセットアップすると、実際に公開できることがわかりました。 EF6を備えたMVC5。

私は自分で数回それを行いましたが、Asp.Net Identityバージョン1.0.0でのみ難しいので、新しいバージョンのサポートを保証することはできません。

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

TOP 一覧

  1. 1

    Unity:未知のスクリプトをGameObject(カスタムエディター)に動的にアタッチする方法

  2. 2

    セレンのモデルダイアログからテキストを抽出するにはどうすればよいですか?

  3. 3

    Ansibleで複数行のシェルスクリプトを実行する方法

  4. 4

    tkinterウィンドウを閉じてもPythonプログラムが終了しない

  5. 5

    Crashlytics:コンパイラー生成とはどういう意味ですか?

  6. 6

    GoDaddyでのCKEditorとKCfinderの画像プレビュー

  7. 7

    Windows 10 Pro 1709を1803、1809、または1903に更新しますか?

  8. 8

    Chromeウェブアプリのウェブビューの高さの問題

  9. 9

    モーダルダイアログを自動的に閉じる-サーバーコードが完了したら、Googleスプレッドシートのダイアログを閉じます

  10. 10

    Windows 10の起動時間:以前は20秒でしたが、現在は6〜8倍になっています

  11. 11

    Reactでclsxを使用する方法

  12. 12

    ファイル内の2つのマーカー間のテキストを、別のファイルのテキストのセクションに置き換えるにはどうすればよいですか?

  13. 13

    MLでのデータ前処理の背後にある直感

  14. 14

    グラフからテーブルに条件付き書式を適用するにはどうすればよいですか?

  15. 15

    Pythonを使用して同じ列の同じ値の間の時差を取得する方法

  16. 16

    mutate_allとifelseを組み合わせるにはどうすればよいですか

  17. 17

    ネットワークグラフで、ネットワークコンポーネントにカーソルを合わせたときに、それらを強調表示するにはどうすればよいですか?

  18. 18

    テキストフィールドの値に基づいて UIslider を移動します

  19. 19

    BLOBストレージからデータを読み取り、Azure関数アプリを使用してデータにアクセスする方法

  20. 20

    PowerShellの分割ファイルへのヘッダーの追加

  21. 21

    ソートされた検索、ターゲット値未満の数をカウント

ホットタグ

アーカイブ