Error loading Azure Active Directory web form: Server returned a 401 status code for the requested resource

I recently made changes to my web site (incorporating a web form and entity framework) to use AAD connection, following the guidance in this insightful blog post.

However, I am encountering an issue where scripts and css files are not loading properly. The server is responding with a 401 error for base.css, jquery-3.1.1.min.js...

To troubleshoot, I updated the authentication mode in my web.config file and disabled all forms of authentication (Anonymous, windows...) in IIS. I also granted full control rights to the project folder.

Interestingly, when I enabled anonymous authentication as a test, the site worked temporarily but reverted back to formatting issues when accessed from another browser. This behavior baffles me.

Could someone offer assistance? Is there something I need to adjust in IIS or elsewhere?

Thank you for any help.

Update: I have assigned a technical user permissions on the project folder through the app pool identity. However, it seems that Azure AD users are still being used and lack the required access rights. How can I ensure that my technical user is utilized after any Azure AD user logs into the website?

Answer №1

Attempting to retrieve CSS/static resources? If they are protected by authentication, it is unlikely that Chrome (or any other browser) would be able to authenticate using OWIN.

This may be why you are able to access them anonymously.

It appears that OWIN is authenticating the XHR requests, but Chrome is attempting to directly access assets – and failing to provide the necessary authentication, resulting in a 401 error.

Answer №2

1- After reviewing the information provided, it seems that if you are using AAD then the issue most likely lies in the "Authentication / Authorization" process for accessing resources. If you are utilizing the Owin library alongside Azure AD, the problem could arise when manually sending an access token that is not being accepted.

2-

Please verify the configuration data for the Web Api. It should resemble the following structure based on your parameters:


  "AzureAd": {
    "Instance": "https://login.microsoftonline.com/",
    "Domain": "myportal.onmicrosoft.com",
    "TenantId": "mytenant-guid",
    "ClientId": "https://myportal.onmicrosoft.com/test_core_web_api_spa"
  },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to pass a variable in an AJAX function call when making a POST request?

I am facing an issue with sending a variable through an ajax function. The scenario is as follows: <a href="next.php" onclick="sendajax()">reload</a> I need to send this variable via the POST method in my php page: <script> fu ...

Extract the input value from the bootstrap-datepicker using JavaScript

I'm working on a Ruby-on-Rails project and I want to include a string from the bootstrap datepicker into a hidden field. However, I am unsure of how to reference an input class in this process. Below is the structure of my form: <%= simple_form_f ...

How to direct all wildcard paths to a particular route in Next.js

I currently have a single landing page application built with nextJs. I am wondering if it is possible to redirect all paths to specific routes, similar to how we do it in react-router. How can I achieve the same functionality in nextJs? <BrowserRou ...

The casperjs evaluate function isn't able to provide me with the necessary data I

Having trouble getting my function to return data correctly. I am trying to retrieve the value of this input box. <input type="text" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b6e736a667b6764646025686466">[em ...

Ensuring the website retains the user's chosen theme upon reloading

I have been developing a ToDo App using MongoDB, EJS, and Node JS. My current challenge involves implementing a theme changer button that successfully changes colors when clicked. However, whenever a new item is added to the database, the page reloads caus ...

Execute a remote PowerShell command using C#

I'm having trouble running an invoke-command cmdlet in C# and I'm struggling with the correct syntax. My goal is to execute this simple command: invoke-command -ComputerName mycomp.mylab.com -ScriptBlock {"get-childitem C:\windows"} In my ...

Integrate your React Native application with a Node.js backend on your local machine

My attempt to establish a connection between my react native app and my node.js app on a Windows system has hit a roadblock. While I am able to receive responses from the node API using Postman, the response from the react native app is coming back as unde ...

Having difficulty manually concealing the launch image on the physical device

When testing my trigger.io app on the Android simulator or my Nexus phone, I can manually hide the launch image through code successfully. However, when running the app on the iOS simulator, the launch image remains visible. Additionally, when debugging di ...

How can I center the window vertically based on the middle of an element?

Hey guys, I need some help with my code. I've been trying to create a button that will shift the window's Y position to center the "Box - 5" div vertically through an onclick event. Basically, I want to make sure the "Box - 5" div is positioned i ...

Is there a way to determine where a Javascript event originated from when it was triggered programmatically?

In my current debugging situation, I am investigating why pressing Enter on a submit button triggers a 'click' event on that same button. It appears that the click event is being fired programmatically, which is the expected behavior in the appli ...

Preventing event propagation in Angular when clicking

What is the best way to call an Angular function within my jQuery code? I attempted to do so with the following: $(document).on('click', '.myBtn', function(e) { angular.element($(".someClass")).scope().clearBtnItems(); e.stop ...

requiring a page reload for an AJAX-loaded webpage

Encountering an issue with a third-party integration on a website specifically designed for iPads, where multiple pages are loaded using AJAX. Upon visiting the page for the first time, the expected functionality is missing and only appears after refreshi ...

Completes a form on a separate website which then populates information onto a different website

Creating a website that allows users to login and view various complaint forms from government websites or other sources. When a user clicks on a link to file a complaint, they will be redirected to the respective page. However, I am looking for a way to ...

Incorporating an element into a nested array

I have an array stored in a variable called 'items' with various products and their attributes. I am looking to randomly generate a popularity score between 1 and 100 for the items that currently do not have one. This is my current array: const ...

Showing information from a database while incorporating line breaks with the help of nl2br

Having trouble with the previous question, so I'll provide more detail here. Below is my index.php file where I explain the method used to save data to a database. <html> <head> <script> function updategroup() { var update_c ...

Exploring Karma and Jasmine for Testing Angular Controllers Module

In an attempt to test my application, I have each controller defined in its own module rather than as a controller of the main app module, and then loaded as a dependency of the main app module. While running a test to check if the loginController is defin ...

Executing a component's function from a JavaScript file

Is it possible in React to call a function or method of a component from a separate JS file in order to modify the component's state? Here are three example files: First, App.js import React,{Component} from 'react'; import Login from &ap ...

What manner must I understand this syntax?

After stumbling upon this code snippet online, I was left scratching my head: function cjsDetectionPlugin() { return { name: 'cjs-detection', moduleParsed({ id, meta: { commonjs: { isCommonJS } } }) { ...

Adjust date by one day using the Datetimepicker tool

I have been attempting to adjust the date of my input by one day either forward or backwards, but I seem to be stuck and not making any progress. Take a look at my code: function function backDay() { var date = $('input#datetimepicker').va ...

verifying an email address through firebase using the verifyPasswordResetCode method

Currently in the process of setting up firebase authentication. Instead of relying on firebase's default pages for recovery password and email verification, I want to handle these processes directly on my website. To customize the recovery steps: U ...