Sitecore Identity Server: Sorry, There Was an Error

After restoring the upgraded database to the SQL, I tried to login into the Sitecore CMS. The identity server comes with an error "Sorry, there was an error" after successful login.

identity-server-error

I have checked the Identity server logs files and found the error: CORS policy execution failed.

ClientConnectionId:fa510858-a9fe-459f-8834-b552574475d8
Error Number:4060,State:1,Class:11
2022-11-02T15:23:19.2788337+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) CORS policy execution failed.
2022-11-02T15:23:19.2790071+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request origin "null" does not have permission to access the resource.
2022-11-02T15:23:19.2792372+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) No CORS policy found for the specified request.
2022-11-02T15:23:19.2796436+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executing endpoint '"Sitecore.Plugin.IdentityServer.Controllers.HomeController.Error (Sitecore.Plugin.IdentityServer)"'
2022-11-02T15:23:19.2844056+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Route matched with "{action = \"Error\", controller = \"Home\"}". Executing controller action with signature "System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Error(System.String)" on controller "Sitecore.Plugin.IdentityServer.Controllers.HomeController" ("Sitecore.Plugin.IdentityServer").
2022-11-02T15:23:19.6316092+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executing ViewResult, running view "Error".
2022-11-02T15:23:19.7299048+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executed ViewResult - view "Error" executed in 437.865ms.
2022-11-02T15:23:19.7302292+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executed action "Sitecore.Plugin.IdentityServer.Controllers.HomeController.Error (Sitecore.Plugin.IdentityServer)" in 445.5762ms
2022-11-02T15:23:19.7303714+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executed endpoint '"Sitecore.Plugin.IdentityServer.Controllers.HomeController.Error (Sitecore.Plugin.IdentityServer)"'
2022-11-02T15:23:19.7317354+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request finished in 892.7288ms 500 text/html; charset=utf-8
2022-11-02T15:23:19.8345691+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request starting HTTP/1.1 GET http://project-identityserver.local/images/warning_yellow.png
2022-11-02T15:23:19.8487507+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Sending file. Request path: '"/images/warning_yellow.png"'. Physical path: '"C:\inetpub\wwwroot\project-identityserver.local\sitecore\Sitecore.Plugin.IdentityServer\Content\images\warning_yellow.png"'
2022-11-02T15:23:19.8490523+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request finished in 14.4892ms 200 image/png
2022-11-02T15:23:24.8506180+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request starting HTTP/1.1 POST http://project-identityserver.local/Account/Login?ReturnUrl=%2Fconnect%2Fauthorize%2Fcallback%3Fclient_id%3DSitecore%26response_type%3Dcode%2520id_token%2520token%26scope%3Dopenid%2520sitecore.profile%26state%3DOpenIdConnect.AuthenticationProperties%253DsQus1tETbSXz9OIlWv3A5E9KCKyIatjo34Uuvo4cXUWGevtGCiTKDwlR9bHBd1wHeY_eP1DEISrgu2MAMNBXMAqm-RnJYyT0gI_PkEtKLbIjdBxK11bT4ldF0ik4EhvhIF9xmVAS3qhc8V2s0Jce8mCP9Ha9ofzDl5500oJHLu9Sb39HJLXCpxqwZNbDx7xaH6WT_ZrcyohoT3OiMEgv4A%26response_mode%3Dform_post%26nonce%3D638029705882534802.ZWNjZmU2MmYtNWIwNi00Y2UxLThmZDItNDc4ZmU1ZDQ0MmE0OGQ5NGVlZTktZTJkMi00YjJhLWExZjUtZjMxMjA0NThlMjg3%26redirect_uri%3Dhttps%253A%252F%252Fproject-cm.local%252Fidentity%252Fsignin%26sc_account_prefix%3Dsitecore%255C%26x-client-SKU%3DID_NET461%26x-client-ver%3D5.3.0.0 application/x-www-form-urlencoded 1001
2022-11-02T15:23:24.8530573+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) CORS policy execution failed.
2022-11-02T15:23:24.8539633+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Request origin "null" does not have permission to access the resource.
2022-11-02T15:23:24.8548308+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) No CORS policy found for the specified request.
2022-11-02T15:23:24.8571113+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executing endpoint '"Sitecore.Plugin.IdentityServer.Controllers.AccountController.Login (Sitecore.Plugin.IdentityServer)"'
2022-11-02T15:23:24.8580584+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Route matched with "{action = \"Login\", controller = \"Account\"}". Executing controller action with signature "System.Threading.Tasks.Task`1[Microsoft.AspNetCore.Mvc.IActionResult] Login(Sitecore.Plugin.IdentityServer.Models.Account.LoginInputModel, System.String)" on controller "Sitecore.Plugin.IdentityServer.Controllers.AccountController" ("Sitecore.Plugin.IdentityServer").
2022-11-02T15:23:24.9345042+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executed action "Sitecore.Plugin.IdentityServer.Controllers.AccountController.Login (Sitecore.Plugin.IdentityServer)" in 75.9275ms
2022-11-02T15:23:24.9348889+08:00 [INF] (Sitecore Identity/HIMMATDULAWAT) Executed endpoint '"Sitecore.Plugin.IdentityServer.Controllers.AccountController.Login (Sitecore.Plugin.IdentityServer)"'
2022-11-02T15:23:24.9355759+08:00 [ERR] (Sitecore Identity/HIMMATDULAWAT) An unhandled exception has occurred while executing the request.
System.Data.SqlClient.SqlException (0x80131904): Cannot open database "MENA_Sitecore_Core" requested by the login. The login failed.
Login failed for user 'sa'.
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at System.Data.ProviderBase.DbConnectionPool.WaitForPendingOpen()
--- End of stack trace from previous location where exception was thrown ---
at IdentityServer4.Contrib.Membership.DataAccess.MembershipContext.Execute[T](IQueryProc`1 args)
at IdentityServer4.Contrib.Membership.DataAccess.MembershipRepository.GetUserPassword(String username)
at IdentityServer4.Contrib.Membership.MembershipService.ValidateUser(String username, String password)
at Sitecore.Plugin.IdentityServer.Controllers.AccountController.GetValidFullUsername(LoginInputModel model)
at Sitecore.Plugin.IdentityServer.Controllers.AccountController.Login(LoginInputModel model, String button)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)

Solution:

Go to the {root-directory}\project-identityserver.local\Config\production and open Sitecore.IdentityServer.Host.xml file and verify the database name.

<SitecoreMembershipOptions>
<ConnectionString>Data Source=HimmatDulawat;Initial Catalog=project_Core_db;User ID=sa;Password=******</ConnectionString>
</SitecoreMembershipOptions>

If it is corrects, then check the <AllowedCorsOrigins> section.

<AllowedCorsOrigins>
<AllowedCorsOriginsGroup1>https://project-cm.local</AllowedCorsOriginsGroup1>
</AllowedCorsOrigins>

In my case it was related to the database name, I forget to update the database name and connection string in the identity server.

Note: Do not forget to recycle the Identity Server App pool.

Happy Sitecoreing 😊

Comments

Popular posts from this blog

Sitecore Installation Error: Failed to Start Service 'Sitecore Marketing Automation Engine'

Import CSV Data in Sitecore Using PowerShell: Part-3

Error: Method Through Reflection is Not Allowed after Applying Sitecore Hotfix