Hello Team,
I am facing an issue with my Blazor application. While using the application, I frequently encounter an “Unauthorized (401)” error.
- Steps to reproduce the issue:
- Log in to the Blazor Admin application and navigate to any page.
- Open the Public Website and refresh the page.
- Return to the Blazor Admin application and try to perform any action.
- At this point, the system shows an Unauthorized (401) error.
I shared the video and log file. Error log link : https://we.tl/t-EnTmS4QUKk Video link : https://we.tl/t-r6s2EwgzzD
4 Answer(s)
-
0
The "Unauthorized (401)" error in your Blazor application is likely caused by session or authentication token conflicts when using multiple applications (Admin and Public Website) that share the same authentication server or cookies.
When you log in to the Admin application and then access the Public Website (which may use a different authentication context or tenant), the authentication cookie or token can be overwritten or invalidated. Returning to the Admin app, your session is no longer valid, resulting in a 401 error.
This is a common scenario in ABP-based applications with tiered or separated authentication, especially when both apps are hosted on the same domain or subdomain and share authentication cookies.
Solution Steps:
Use Different Browsers or Incognito Mode:
- To avoid session conflicts, use separate browsers or incognito/private windows for each application (Admin and Public Website).
Configure Cookie Names and Domains:
- Ensure each application uses a unique authentication cookie name and, if possible, separate domains or subdomains.
- In your
appsettings.json
or authentication configuration, set a unique cookie name for each app:
services.ConfigureApplicationCookie(options => { options.Cookie.Name = "YourAppName.Auth"; // Optionally, set options.Cookie.Domain if using subdomains });
- For Blazor, also check the
AbpApplicationCookieOptions
if using ABP's built-in authentication.
Check Token Storage (for JWT):
- If using JWT tokens (e.g., in localStorage/sessionStorage), ensure each app uses a unique storage key to prevent overwriting tokens.
Review Tenant Context:
- If your applications are multi-tenant, ensure the correct tenant is selected in each app. Switching tenants in one app can affect the authentication context in another.
Logout and Re-login:
- If you encounter a 401, log out from both applications and log in again to re-establish valid sessions.
Additional Debugging:
- Enable detailed authentication logs to trace token/cookie issues.
- Review the logs and video you provided for any specific error messages related to token validation or cookie issues.
Summary:
This issue is caused by authentication/session conflicts between multiple ABP applications sharing the same authentication server or cookie domain. Isolate sessions by using different browsers/incognito windows, or configure unique cookie names/domains for each app.Sources:
This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.
-
0
I have tried these steps but I am still unable to resolve the problem. Please advise.
-
0
hi
Can you try to open these two websites in Chrome and Chrome Incognito?
Thanks.
-
0
Can you share the Debug logs of these two websites?
liming.ma@volosoft.com
See debug logs: https://abp.io/support/questions/8622/How-to-enable-Debug-logs-for-troubleshoot-problems
Thanks.