0

I am trying out the sample code of the Microsoft identity platform to add authentication and authorization to web applications. The sample from the link (https://github.com/Azure-Samples/ms-identity-aspnet-webapp-openidconnect) is working well in IIS Express. When hosting the same application on a custom website in IIS, it is not working as expected. The steps which I have followed, and problems occurred are mentioned below.

HOSTING IN IIS EXPRESS

  1. The following is the landing page of this application. img1

  2. In IIS Express, when clicking Sign in with Microsoft, it prompts for the username and password. img2&3

  3. After entering the credentials, it is being redirected successfully to the index page which is configured in the Web.config file. img4

HOSTING IN CUSTOM IIS WEBSITE

  1. The same application is hosted in a custom website in IIS. img5

  2. Here also while clicking the Sign in with Microsoft, it prompts for username and password

  3. After entering the username and password, it is not redirecting to the configured page (https://localhost/AppTest/) and instead, it is landing in the URL https://localhost/.

  4. Also, the network log of the browser shows that the location header has the value as “/” in the response header of the redirect uri request.

img6

  1. For debugging, I have added a custom middleware. img7

  2. It is used before the UseOpenIdConnectAuthentication as mentioned below. img8

  3. While debugging with Visual Studio, it is observed that after authentication the UseOpenIdConnectAuthentication is making a new unknown redirect request instead of the redirect uri configured in the Web.config and the request and its response have the location path value as “/”.

img9

I cannot understand how this new redirect request arises meanwhile the same app is working well in IIS Express. Please help me to resolve this issue. Thank you.

2 Answers2

1

It is found that while hosting this application in IIS, after authentication, instead of landing in the URL configured in UseOpenIdConnectAuthentication, a new redirect occurs to the URL which is given to the instance of the AuthenticationProperties in the SignIn Action.

Modifying this redirect value in SignIn action solved the problem.

0

For your error,I think the most likely reason is that directory browsing is not enabled,so the program is led to the unknown redirect uri.

So you can past this code snippet inside your web.config file to solve the error.

<system.webServer>
    <directoryBrowse enabled="true" />
</system.webServer>

or you can

1.Open IIS Manager

2.Click the Application

3.Click Directory Browsing

4.Click Open Feature (On the right you will see under Actions)

5.Click Enable

For more information, please refer to this.And you can follow this.

UPDATE

This is where I made the changes to the sample code you provided and some configurations.It works.

enter image description here

enter image description here

enter image description here

Chauncy Zhou
  • 1,010
  • 1
  • 5
  • 10
  • Thanks for the response. After enabling the directory browsing, Still it is not working.. – Prabhakaran G Aug 31 '20 at 16:54
  • @PrabhakaranG I'm sorry I didn't help you, because there are so many reasons for this error, such as incorrect .net framework settings, you can follow the official documentation in my answer, so you can avoid this mistake, thanks. – Chauncy Zhou Sep 01 '20 at 01:50
  • Thanks for the kind response. I will update this issue once I get the resolution – Prabhakaran G Sep 02 '20 at 09:14