繁体   English   中英

登录后的Azure AD SSO重定向

[英]Azure AD SSO Redirection After Login

使用OAUTH和Azure AD进行身份验证后,我无法正确重定向dashboard.aspx页面。 在VS 2017中调试时,我可以使用O365电子邮件和密码登录,并且重定向可以完美地进行。 但是,当我发布到Web服务器时却没有。 该页面似乎只是坐在那里,什么也不做。 我曾尝试将Azure中的重定向URL更改为http://domainame.com/dashboard.aspx,但这不起作用。 我也已经在文件后面的代码中放置了一个重定向语句。 我需要部署此应用程序,这是我需要的最后一步。 这也是使用OWIN。 我使用默认的ASP.NET模板启动该项目,然后从工作或学校中选择身份验证。 以下是StartUpAuth.cs文件。 我将实际的重定向域更改为domain.name.com,仅用于发布目的。 抱歉,如果代码格式不正确。 每次尝试时,无论是否有4个缩进,我仍然会对其投反对票。

namespace HealthScripts
{
    public partial class Startup
    {
        private static string clientId = ConfigurationManager.AppSettings["ida:ClientId"];
        private static string appKey = ConfigurationManager.AppSettings["ida:ClientSecret"];
        private static string aadInstance = ConfigurationManager.AppSettings["ida:AADInstance"];
        private static string tenantId = ConfigurationManager.AppSettings["ida:TenantId"];
        private static string postLogoutRedirectUri = ConfigurationManager.AppSettings["ida:PostLogoutRedirectUri"];

        private string authority = aadInstance + tenantId;
        // This is the resource ID of the AAD Graph API.  We'll need this to request a token to call the Graph API.
        private static string graphResourceId = "https://graph.windows.net";

        public void ConfigureAuth(IAppBuilder app)
        {
            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            app.UseOpenIdConnectAuthentication(
                new OpenIdConnectAuthenticationOptions
                {
                    ClientId = clientId,
                    Authority = authority,
                    PostLogoutRedirectUri = postLogoutRedirectUri,
                    //RedirectUri = "https://domain.name.com/HealthScripts-Staging/",
                    Notifications = new OpenIdConnectAuthenticationNotifications()
                    {
                        //
                        // If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
                        //
                        AuthorizationCodeReceived = (context) =>
                        {
                            var code = context.Code;
                            ClientCredential credential = new ClientCredential(clientId, appKey);
                            string signedInUserID = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;
                            AuthenticationContext authContext = new AuthenticationContext(authority, new ADALTokenCache(signedInUserID));
                            AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
                            code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);

                            return Task.FromResult(0);
                        }
                    }
                }
                );

            // This makes any middleware defined above this line run before the Authorization rule is applied in web.config
            app.UseStageMarker(PipelineStage.Authenticate);
        }
    }
}

 [Win32Exception (0x80004005): The system cannot find the file specified] [SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)] System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling) +1379 System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +452 System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions) +70 System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +927 System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection) +109 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection) +1550 System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) +117 System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection) +258 System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions) +314 System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry) +126 System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry) +255 System.Data.SqlClient.SqlConnection.Open() +128 System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch(TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed) +101 System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext) +509 System.Data.Entity.SqlServer.<>c__DisplayClass33.<UsingConnection>b__32() +561 System.Data.Entity.SqlServer.<>c__DisplayClass1.<Execute>b__0() +15 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Func`1 operation) +231 System.Data.Entity.SqlServer.SqlProviderServices.UsingMasterConnection(DbConnection sqlConnection, Action`1 act) +911 System.Data.Entity.SqlServer.SqlProviderServices.CreateDatabaseFromScript(Nullable`1 commandTimeout, DbConnection sqlConnection, String createDatabaseScript) +117 System.Data.Entity.SqlServer.SqlProviderServices.DbCreateDatabase(DbConnection connection, Nullable`1 commandTimeout, StoreItemCollection storeItemCollection) +211 System.Data.Entity.Migrations.Utilities.DatabaseCreator.Create(DbConnection connection) +125 System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase) +156 System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration) +116 System.Data.Entity.Internal.DatabaseCreator.CreateDatabase(InternalContext internalContext, Func`3 createMigrator, ObjectContext objectContext) +121 System.Data.Entity.Database.Create(DatabaseExistenceState existenceState) +292 System.Data.Entity.CreateDatabaseIfNotExists`1.InitializeDatabase(TContext context) +187 System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action) +69 System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization() +482 System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input) +174 System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action) +269 System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +38 System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +77 System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +21 System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +59 System.Linq.Queryable.FirstOrDefault(IQueryable`1 source, Expression`1 predicate) +61 HealthScripts.Models.ADALTokenCache..ctor(String signedInUserId) in C:\\Users\\tadams\\Desktop\\Important Projects\\HS-MAIN\\HealthScripts\\HealthScripts\\Models\\AdalTokenCache.cs:14 HealthScripts.Startup.<ConfigureAuth>b__7_0(AuthorizationCodeReceivedNotification context) in C:\\Users\\tadams\\Desktop\\Important Projects\\HS-MAIN\\HealthScripts\\HealthScripts\\App_Start\\StartupAuth.cs:54 Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +5389 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 Microsoft.Owin.Security.OpenIdConnect.<AuthenticateCoreAsync>d__1a.MoveNext() +5898 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Security.Infrastructure.<BaseInitializeAsync>d__0.MoveNext() +817 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +329 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +768 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__5.MoveNext() +194 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +60 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__2.MoveNext() +184 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +31 Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +117 System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +365 System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +195 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +128 

如果您的SSO在本地工作,则将无法在已发布的版本中工作,反之亦然。 检查以确保将答复URL设置为Azure门户和代码配置中的已发布应用URL。

作为参考,请参阅以下文档: https : //github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect

“该系统找不到指定的文件。” 此错误消息表示客户端可以访问服务器,但是目标计算机上没有具有特定管道名称的命名管道侦听器。 这也意味着该帐户可以毫无问题地进行文件共享会话。

可能的原因是:

a)输入实例名称错误或实例名称错误。 实例名称不是您要定位的名称。 请注意,对于默认实例,不应使用MSSQLSERVER作为实例名称。

b)目标SQL Server未运行

c)服务器上未启用命名管道。

d)您使用的是不同版本,并且缺少依赖项。

确保可以使用SSMS手动连接到SQL Server。 如果是这样,则更新应用程序的web.config中的连接字符串。 如果无法使用SSMS连接到SQL Server,则需要对问题进行故障排除: https : //social.technet.microsoft.com/wiki/contents/articles/2102.how-to-troubleshoot-connecting-to-the- SQL服务器数据库,engine.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM