![](/img/trans.png)
[英]Server Error Resource cannot be found 404 when trying to access directory using HTTPS on IIS 8.5 but works using HTTP
[英]Cannot create DB using EntityFramework 6 when the project is deployed on an IIS 8.5
我有一個 Visual Studio 2019 項目,該項目使用 ASP.NET 和 C# 發布了 web 應用程序(web api)。
我們使用 EntityFramework 6 Code-First 策略來訪問 SQL 服務器數據庫。
When I run it locally or on an Azure Service, everything is great, but when I deploy this web app onto an IIS 8.5 in a server running Windows Server 2012 R2, for some reason EntityFramework 6 is not able to create the database.
我們使用以下內容創建數據庫:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MobileServiceContext, Migrations.Configuration>("MS_TableConnectionString"));
我們指向的是本地 SQL Server 2014。
我們創建一個 DbContext 的子級來處理 EntityFramework 上下文,如下所示:
public class MobileServiceContext : DbContext
{
public const string CONNECTION_STRING_KEY = "MS_TableConnectionString"; // "MS_TableConnectionString";
public const string CONNECTION_STRING_NAME = "Name=" + CONNECTION_STRING_KEY; // "MS_TableConnectionString";
public MobileServiceContext() : base(CONNECTION_STRING_NAME)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
... we add some logic here to create indexes etc.
}
}
當我嘗試在服務器上遠程調試應用程序時,在第一次創建 MobileServiceContext 類型的 object 時,執行只是沒有提前 go (我什至嘗試在創建時添加 ZA75131CB1C90CDAFC1C0A52AE24Z,但它沒有'不要進入異常捕獲...)。
顯然我們從來沒有進入 OnModelCreating 方法......
同樣,相同的代碼在本地和 Azure 上都能完美運行。
我應該在我的服務器中配置任何東西嗎?
只是為了記錄,事實證明我必須在 web.config 中添加以下重定向:
<dependentAssembly>
<!-- Don't change this redirect!! It is part of a problem with a MS bug, see here https://github.com/dotnet/corefx/issues/25773 -->
<assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.