Open Closed

How to get a JSON response on 401 / Unauthorized #5983


User avatar
0
BassaSolutions created
  • ABP Framework version: v6.0.3
  • UI type: Blazor
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no

When sending X-Requested-With :XMLHttpRequest in the header, the correct status is responded when unauthorized: 401 instead of 200.

But the content is still the HTML page:

...
<div class="col">
					<div class="status-content">
						<h1>401</h1>
						<h2 class="text-danger mb-0">
							Unauthorized<small class="text-muted">An internal error occurred during your request!</small>
						</h2>
						<p class="mt-3 mb-4"></p>
						<a href="/" class="btn btn-primary">Go to the homepage</a>
						<a href="javascript:history.back()"
							class="mt-4 mb-1 d-block"><i class="fa fa-long-arrow-left"></i> Go back</a>
					</div>
				</div>
...

How can I get a the default error JSON response content?

{
  "error": {
    "message": "Some error message"
  }
}

I tried to send additional headers: Content-Type: application/json Accept: application/json

But the content is always HTML.

Thank you for your help!

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Hello BassaSolutions,

    could you please provide steps to reproduce.

    Regards,

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    BassaSolutions created
    1. Load startup template
    2. Call any authorized endpoint with postman (without authorization). Add header: X-Requested-With :XMLHttpRequest
    3. Response content is HTML (target: JSON)
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Member

    Hello BassaSolutions,

    Please check this similar issue https://support.abp.io/QA/Questions/3281/Swagger-Authorisation--401-Response-instead-of-login-page-redirect#

    Regards,

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 28, 2026, 11:44
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.