簡體   English   中英

web.config 到一個 SQL DB 的兩個連接字符串在調試中工作,但在發布時不起作用

[英]Two connection strings in web.config to one SQL DB work in debug but not when published

我正在嘗試將 asp 身份添加到一個非常基本的 MVC 站點,該站點當前包含來自 SQL 數據庫的單個表。

SQL 被添加為 ADO.NET 實體數據 Model,使用數據庫中的 EF 設計器,我可以從我的 MVC 站點讀取和寫入而不會出現問題)(在本地開發和發布后)。

然后我添加了 asp.net 身份,這添加了一個有效的本地數據庫文件。

然后,我嘗試將身份表遷移到我的主 SQL 服務器,這樣我只需要維護一個數據庫(網站的托管和 SQL 數據庫都使用同一個提供商)。

我設法在主 SQL DB 中創建了表,並在我的 web.config 中添加了第二個連接字符串,以允許 asp 身份和我現有的 edmx 設置工作(如果我嘗試通過 EF 連接字符串運行 asp 身份 I得到錯誤“實體類型 ApplicationUser 不是當前上下文的 model 的一部分。”)。 然后我刪除了本地數據庫文件以確保。

在我的客戶端上進行測試(使用兩個連接字符串)時,我可以創建帳戶、登錄和退出並按預期使用 asp.identity,還可以看到主 SQL 數據庫中的身份表正在填充。 我還可以使用我的通用 EF 連接來讀取和寫入數據庫的核心 MVC 站點。

但是,當我發布到主站點時,無論我調用身份還是 EF DB function 我都會收到錯誤消息

錯誤。 處理您的請求時發生錯誤。

它顯示在渲染頁面上/內聯(我嘗試在 web.config 中打開自定義錯誤,但這似乎沒有給我更多細節。)

我的兩個連接字符串如下所示(我假設這是問題所在?)我還需要web.config中的其他內容嗎? 還是我錯過了一些基本的東西?

<connectionStrings>
   <add name="BDIdentityString" connectionString="Data Source=IPADDRESS; Initial Catalog=DBNAME; User ID=USERNAME; Password=PASSWORD; Connect Timeout=60;" providerName="System.Data.SqlClient" />
   <add name="BDString" connectionString="metadata=res://*/Models.DBENTITYNAME.csdl|res://*/Models.DBENTITYNAME.ssdl|res://*/Models.DBENTITYNAME.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=IPADDRESS;initial catalog=DBNAME;user id=USERNAME;password=PASSWORD;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
 </connectionStrings>

更新:

所以我終於得到了自定義錯誤(認為我在某處有錯字),錯誤發布在下面。 作為測試,我使用我的項目的備份副本在不引入身份的情況下再次測試 EF DB 查詢 - 發布並實時測試。 再次,這一切都按預期工作。 然后我恢復了我當前的構建並添加了身份並回到相同的問題。 (在項目的兩個版本中,EF 的連接字符串保持不變)

為了清楚起見,我正在使用 fasthosts.co.uk,在我的測試中,我通過讀取和寫入由我的客戶的 fasthosts 托管的實時 SQL DB 來做到這一點。 與發布到 fasthosts 時沒有身份的備份版本一樣,仍然能夠連接和讀取/寫入 SQL DB。

我正在使用他們的 Momentum package,因此包含了從我擁有的本地 IIS 服務器生成的所需的 machineKey。 此密鑰在沒有身份的版本 1 和有身份的版本 2 中都存在。

我還嘗試將以下內容添加到 AssemblyInfo.cs

[assembly: AllowPartiallyTrustedCallers]
[assembly: SecurityRules(SecurityRuleSet.Level1)]

(fasthosts 推薦的 AllowPartiallyTrustedCallers 用於安全異常描述類型錯誤)

關閉 customerErrors 后,我會得到兩個不同的響應,這取決於我是通過身份調用數據庫還是從我的 MVC 代碼中的 EF 調用調用數據庫。 錯誤是這樣的:

EF錯誤:

erver Error in '/' Application.

Operation could destabilize the runtime. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Security.VerificationException: Operation could destabilize the runtime.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[VerificationException: Operation could destabilize the runtime.]
   System.Data.Entity.Core.Metadata.Edm.FacetDescription.Validate(String declaringTypeName) +70
   System.Data.Entity.Core.Metadata.Edm.FacetDescription..ctor(String facetName, EdmType facetType, Nullable`1 minValue, Nullable`1 maxValue, Object defaultValue, Boolean isConstant, String declaringTypeName) +103
   System.Data.Entity.Core.SchemaObjectModel.FacetDescriptionElement.CreateAndValidateFacetDescription(String declaringTypeName) +115
   System.Data.Entity.Core.SchemaObjectModel.TypeElement.ResolveTopLevelNames() +119
   System.Data.Entity.Core.SchemaObjectModel.Schema.ResolveTopLevelNames() +206
   System.Data.Entity.Core.SchemaObjectModel.Schema.Resolve() +16
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +553
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, IList`1& schemaCollection) +156
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest(XmlReader xmlReader, String location, Boolean checkForSystemNamespace, Schema& schema) +139
   System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader reader) +75
   System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor(XmlReader reader) +116
   System.Data.Entity.SqlServer.SqlProviderManifest..ctor(String manifestToken) +37
   System.Data.Entity.SqlServer.<>c.<GetDbProviderManifest>b__29_0(String s) +25
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +73
   System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest(String versionHint) +124
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +55

[ProviderIncompatibleException: The provider did not return a ProviderManifest instance.]
   System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken) +186
   System.Data.Entity.Core.Metadata.Edm.Loader.InitializeProviderManifest(Action`3 addError) +312
   System.Data.Entity.Core.Metadata.Edm.Loader.OnProviderManifestTokenNotification(String token, Action`3 addError) +33
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleProviderManifestTokenAttribute(XmlReader reader) +97
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleAttribute(XmlReader reader) +184
   System.Data.Entity.Core.SchemaObjectModel.SchemaElement.ParseAttribute(XmlReader reader) +185
   System.Data.Entity.Core.SchemaObjectModel.SchemaElement.Parse(XmlReader reader) +76
   System.Data.Entity.Core.SchemaObjectModel.Schema.HandleTopLevelSchemaElement(XmlReader reader) +37
   System.Data.Entity.Core.SchemaObjectModel.Schema.InternalParse(XmlReader sourceReader, String sourceLocation) +739
   System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation) +58
   System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection) +340
   System.Data.Entity.Core.Metadata.Edm.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths) +158
   System.Data.Entity.Core.Metadata.Edm.Loader..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver) +127
   System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest& providerManifest, DbProviderFactory& providerFactory, String& providerInvariantName, String& providerManifestToken, Memoizer`2& cachedCTypeFunction) +131
   System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths) +223
   System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader) +88
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass9_1.<GetMetadataWorkspace>b__1() +14
   System.Lazy`1.CreateValue() +429
   System.Lazy`1.LazyInitValue() +158
   System.Lazy`1.get_Value() +79
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass9_1.<GetMetadataWorkspace>b__4() +9
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection(Func`1 itemCollectionLoader) +16
   System.Data.Entity.Core.Metadata.Edm.<>c__DisplayClass12_0.<.ctor>b__3() +21
   System.Lazy`1.CreateValue() +429
   System.Lazy`1.LazyInitValue() +158
   System.Lazy`1.get_Value() +79
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required) +95
   System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace) +12
   System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner) +46
   System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory) +575
   System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel() +65
   System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel() +21
   System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +506
   System.Data.Entity.Internal.InternalContext.Initialize() +20
   System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16
   System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +53
   System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
   System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName) +62
   System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity) +108
   System.Data.Entity.DbSet`1.Add(TEntity entity) +72
   HotBrewCrew.Controllers.HomeController.Register(interested_parties fromForm) in C:\Users\ewilson\Documents\Development\HotBrewCrew\HotBrewCrew\Controllers\HomeController.cs:26
   lambda_method(Closure , ControllerBase , Object[] ) +100
   System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +14
   System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +166
   System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
   System.Web.Mvc.Async.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +22
   System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58
   System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9839161
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

和身份錯誤

Server Error in '/' Application.

Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[TypeLoadException: Inheritance security rules violated while overriding member: 'Microsoft.AspNet.Identity.TaskExtensions+CultureAwaiter`1<T>.UnsafeOnCompleted(System.Action)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.]
   Microsoft.AspNet.Identity.Owin.SignInManager`2.PasswordSignInAsync(String userName, String password, Boolean isPersistent, Boolean shouldLockout) +0
   HotBrewCrew.Controllers.<Login>d__11.MoveNext() in C:\Users\ewilson\Documents\Development\HotBrewCrew\HotBrewCrew\Controllers\AccountController.cs:74
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97
   System.Web.Mvc.Async.<>c__DisplayClass8_0.<BeginInvokeAsynchronousActionMethod>b__1(IAsyncResult asyncResult) +17
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32
   System.Web.Mvc.Async.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0() +58
   System.Web.Mvc.Async.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2() +228
   System.Web.Mvc.Async.<>c__DisplayClass7_0.<BeginInvokeActionMethodWithFilters>b__1(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34
   System.Web.Mvc.Async.<>c__DisplayClass3_6.<BeginInvokeAction>b__4() +35
   System.Web.Mvc.Async.<>c__DisplayClass3_1.<BeginInvokeAction>b__1(IAsyncResult asyncResult) +100
   System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
   System.Web.Mvc.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState) +11
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +45
   System.Web.Mvc.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller) +13
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
   System.Web.Mvc.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState) +28
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9839161
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +50
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.3928.0 

更新 2

這可能是 fasthosts 的信任問題。 我剛剛建立了一個啟用身份的開箱即用 MVC 站點。 將連接字符串更改為指向 SQL DB - 再次在開發環境中工作(從主項目開發測試中注冊的詳細信息),但在沒有其他更改的情況下實時推送時失敗。

我會努力詢問托管服務提供商,但我不是 100% 相信這是我唯一/或實際的問題,因為 EF 在沒有身份的情況下工作,只是沒有在項目中安裝身份。

As expected the limitation was with https://www.fasthosts.co.uk/ - Moving my site with no code changes (other than the SQL connection string to reflect the new SQL server) with provider https://hostinguk.net/該網站工作沒有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM