我想创建一个使用Azure AD进行身份验证的简单应用程序。
我决定通过Visual Studio做到这一点,所以我:
为清楚起见,这是我的web.config(生成):
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-xxx-20180626122432.mdf;Initial Catalog=aspnet-xxx-20180626122432;Integrated Security=True" 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" />
<add key="ida:ClientId" value="e9xx-xxx-xxxf-9xxd-xxx" />
<add key="ida:AADInstance" value="https://login.microsoftonline.com/" />
<add key="ida:ClientSecret" value="xxxA=" />
<add key="ida:Domain" value="xxx.onmicrosoft.com" />
<add key="ida:TenantId" value="xxx-fxxa-xxe7-9xxx-xxx" />
<add key="ida:PostLogoutRedirectUri" value="https://xxx.azurewebsites.net" />
</appSettings>
为什么甚至生成连接字符串?我不需要数据库,这也是导致我收到错误的原因。
据我所知应该就是这样。但是,当我登录自己的网站时,出现以下错误:
[Win32Exception(0x80004005):系统找不到文件 指定]
[SqlException(0x80131904):与网络有关或与实例有关的 建立与SQL Server的连接时发生错误。的 找不到服务器或无法访问服务器。验证实例 名称正确并且该SQL Server配置为允许远程 连接。 (提供者:SQL网络接口,错误:52-无法 找到本地数据库运行时安装。验证SQL Server Express已正确安装,并且本地数据库运行时 功能已启用。)]
System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity 身份,SqlConnectionString connectionOptions,SqlCredential 凭证,对象providerInfo,字符串newPassword,SecureString newSecurePassword,布尔型redirectedUserInstance,SqlConnectionString userConnectionOptions,SessionData reconnectSessionData, DbConnectionPool池,字符串accessToken,布尔值 applyTransientFaultHandling)+821
System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions 选项,DbConnectionPoolKey poolKey,对象poolGroupProviderInfo, DbConnectionPool池,DbConnection owningConnection, DbConnectionOptions userOptions)+332
System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool 池,DbConnection owningObject,DbConnectionOptions选项, DbConnectionPoolKey poolKey,DbConnectionOptions userOptions)+38
System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject,DbConnectionOptions,userOptions,DbConnectionInternal oldConnection)+699
System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject,DbConnectionOptions,userOptions,DbConnectionInternal oldConnection)+89
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,UInt32 waitForMultipleObjectsTimeout,布尔值 allowCreate,仅布尔值OneCheckConnection,DbConnectionOptions userOptions,DbConnectionInternal&连接)+426
System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject,TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +78
1重试,DbConnectionOptions userOptions,DbConnectionInternal oldConnection,DbConnectionInternal& 连接)+191
System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource
System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection externalConnection,DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) +154
1重试,DbConnectionOptions userOptions)+21
System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource
System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource1 retry) +90
1 重试)+209 System.Data.SqlClient.SqlConnection.Open()+96
System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.b__36(DbConnection t,DbConnectionInterceptionContext c)+10
System.Data.Entity.Infrastructure.Interception.InternalDispatcher1.Dispatch(TTarget target, Action
2操作,TInterceptionContext拦截上下文, 行动3 executing, Action
3已执行)+72
System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection 连接,DbInterceptionContext拦截上下文)+360
System.Data.Entity.SqlServer。<> c__DisplayClass33.b__32() +426 System.Data.Entity.SqlServer。<> c__DisplayClass1.b__0()+10
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func1 operation) +189
1动)+175
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation) +78
System.Data.Entity.SqlServer.SqlProviderServices.UsingConnection(DbConnection sqlConnection, Action
System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection,操作1 act) +552
1 commandTimeout,DbConnection,sqlConnection,字符串 createDatabaseScript)+90
System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable
System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection 连接,可空1 commandTimeout, StoreItemCollection storeItemCollection) +171
1 commandTimeout,StoreItemCollection storeItemCollection)+76
System.Data.Entity.Core.Common.DbProviderServices.CreateDatabase(DbConnection connection, Nullable
System.Data.Entity.Core.Objects.ObjectContext.CreateDatabase()+134
System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection 连接)+119
System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(动作 mustSucceedToKeepDatabase)+142
System.Data.Entity.Migrations.DbMigrator.Update(字符串 targetMigration)+78
System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext,Func3 createMigrator, ObjectContext objectContext) +89 System.Data.Entity.Internal.InternalContext.CreateDatabase(ObjectContext objectContext, DatabaseExistenceState existenceState) +116
1.InitializeDatabase(TContext 上下文)+151
System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +218
System.Data.Entity.CreateDatabaseIfNotExists
System.Data.Entity.Internal。<> c__DisplayClassf1.<CreateInitializationAction>b__e() +76 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +60
1.PerformAction(TInput输入) +110 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(动作
System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +357 System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c) +7
System.Data.Entity.Internal.RetryAction1 action) +198
1.Initialize()+53
System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase() +73 System.Data.Entity.Internal.InternalContext.Initialize() +30 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +16
System.Data.Entity.Internal.Linq.InternalSet
System.Data.Entity.Internal.Linq.InternalSet1.get_InternalContext() +15 System.Data.Entity.Infrastructure.DbQuery
1.System.Linq.IQueryable.get_Provider() +38 System.Linq.Queryable.FirstOrDefault(IQueryable1 source, Expression
1谓词)+83
AdAuthPocDamco.Models.ADALTokenCache..ctor(StringsignedInUserId)在 c:\ users \ manielse \ source \ repos \ AdAuthPocDamco \ AdAuthPocDamco \ Models \ AdalTokenCache.cs:26 AdAuthPocDamco.Startup.b__7_0(AuthorizationCodeReceivedNotification 上下文中) c:\ users \ manielse \ source \ repos \ AdAuthPocDamco \ AdAuthPocDamco \ App_Start \ Startup.Auth.cs:54 Microsoft.Owin.Security.OpenIdConnect.d__1a.MoveNext() +4952 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()+26
Microsoft.Owin.Security.OpenIdConnect.d__1a.MoveNext() +6433 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext() +571 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext()+255
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +182 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Security.Infrastructure.d__0.MoveNext()+638
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__5.MoveNext() +182 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务 任务)+99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务 任务)+61
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.d__2.MoveNext() +180 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar)+69
Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar)+64
System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +380 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep步骤)+48 System.Web.HttpApplication.ExecuteStep(IExecutionStep 步骤,布尔值和已同步完成)+159
答案 0 :(得分:0)
为什么甚至生成连接字符串?
我无法复制您提到的问题。在我的web.config文件中,没有创建数据库连接字符串。而且它在我这边正常工作。
我不需要数据库,这似乎也是导致我收到错误的原因。
是的,您是对的。由于默认情况下Azure WebApp无法连接到本地数据库。
如果您不需要数据库,则可以在发布到Azure WebApp的过程中删除SQL连接。或者,您可以创建另一个Web项目,然后重试。