Skip to content

Commit e39b1fa

Browse files
authored
Update asp-dot-net-application-infinite-sign-in-loop.md
1 parent c27f49e commit e39b1fa

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

support/entra/entra-id/app-integration/asp-dot-net-application-infinite-sign-in-loop.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Infinite sign-in loop between ASP.NET application and Microsoft Entra ID
2+
title: Infinite Sign-in Loop Between ASP.NET Application and Microsoft Entra ID
33
description: Helps you resolve an infinite sign-in loop issue between an ASP.NET application and with Microsoft Entra ID when performing sign in.
4-
ms.date: 04/23/2025
4+
ms.date: 04/25/2025
55
ms.author: bachoang
66
ms.service: entra-id
77
ms.custom: sap:Developing or Registering apps with Microsoft identity platform
@@ -13,27 +13,27 @@ This article provides solutions to an issue where an ASP.NET application experie
1313

1414
## Symptoms
1515

16-
An ASP.NET application running an old version of OWIN middleware fails to recognize an authenticated request from Microsoft Entra ID.  It keeps sending the request back to Microsoft Entra ID for signing in, leading to the infinite loop issue. The following error message might be displayed in the browser:
16+
An ASP.NET application running an earlier version of Open Web Interface for .NET (OWIN) middleware fails to recognize an authenticated request from Microsoft Entra ID.  It keeps sending the request back to Microsoft Entra ID for signing in, leading to the infinite loop issue. The following error message might be displayed in the browser:
1717

1818
> We couldn't sign you in. Please try again.
1919
2020
## Cause
2121

22-
This issue occurs due to a cookie mismanagement issue (a [known Katana bug](https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues)) in the old version of OWIN.
22+
This issue occurs due to a cookie mismanagement issue (a [known Katana bug](https://github.com/aspnet/AspNetKatana/wiki/System.Web-response-cookie-integration-issues)) in the earlier version of OWIN.
2323

2424
### How to recognize the Katana bug
2525

26-
Capture a Fiddler trace and examine one of the later redirect frames back to the web application. Note in the following screenshot, the request in frame 58 contains multiple OpenIdConnect.nonce cookies (red-circled). In a working scenario, you should only have one OpenIdConnect.nonce cookie set at the beginning before authentication. After the request is successfully authenticated, this nonce cookie is destroyed and ASP.NET sets its own session cookie. Because of this bug, you see there is a build up of these nonce cookies.
26+
Capture a Fiddler trace and examine one of the later redirect frames back to the web application. Note in the following screenshot, the request in frame 58 contains multiple OpenIdConnect.nonce cookies (red-circled). In a working scenario, you should only have one OpenIdConnect.nonce cookie set at the beginning before authentication. After the request is successfully authenticated, this nonce cookie is destroyed and ASP.NET sets its own session cookie. Because of this bug, you see a buildup of these nonce cookies.
2727

2828
:::image type="content" source="media/asp-dot-net-application-infinite-sign-in-loop/openidconnet-nonce-cookies.png" alt-text="Screenshot that shows multiple OpenIdConnect nonce cookies." lightbox="media/asp-dot-net-application-infinite-sign-in-loop/openidconnet-nonce-cookies.png":::
2929

3030
## Solution 1: Upgrade to ASP.NET Core
3131

32-
The issue has been resolved in ASP.NET Core and a newer version of Katana OWIN for ASP.NET. To resolve this issue, upgrade your application to use ASP.NET Core.
32+
The issue is resolved in ASP.NET Core and a later version of Katana OWIN for ASP.NET. To resolve this issue, upgrade your application to use ASP.NET Core.
3333

34-
If you must continue to use ASP.NET, perform the following things:
34+
If you must continue to use ASP.NET, perform the following actions:
3535

36-
- Update your application's Microsoft.Owin.Host.SystemWeb package to be at least version 3.1.0.0.
36+
- Update your application's Microsoft.Owin.Host.SystemWeb package to version 3.1.0.0 or later.
3737
- Modify your code to use one of the new cookie manager classes, for example:
3838

3939
```csharp
@@ -44,8 +44,6 @@ If you must continue to use ASP.NET, perform the following things:
4444
});
4545
```
4646

47-
Or
48-
4947
```csharp
5048
app.UseCookieAuthentication(new CookieAuthenticationOptions()
5149
{
@@ -55,13 +53,13 @@ If you must continue to use ASP.NET, perform the following things:
5553

5654
## Solution 2: Correct the redirect URL
5755

58-
In some cases where the application is hosted under a virtual directory or an application instead of the root of the web site, the [solution 1](#solution-1-upgrade-to-aspnet-core) might not work. For more information, see [Infinite re-direct loop after AAD Authentication when redirect is specified](https://stackoverflow.com/questions/44397715/infinite-re-direct-loop-after-aad-authentication-when-redirect-is-specified) and [Microsoft Account OAuth2 sign-on fails when redirect URL is not under the website root](https://github.com/aspnet/AspNetKatana/issues/203).
56+
In some cases where the application is hosted under a virtual directory or an application instead of the root of the web site, [solution 1](#solution-1-upgrade-to-aspnet-core) might not work. For more information, see [Infinite re-direct loop after AAD Authentication when redirect is specified](https://stackoverflow.com/questions/44397715/infinite-re-direct-loop-after-aad-authentication-when-redirect-is-specified) and [Microsoft Account OAuth2 sign-on fails when redirect URL is not under the website root](https://github.com/aspnet/AspNetKatana/issues/203).
5957
6058
For example, suppose you have the following environment:
6159

6260
- The root of a web site: `https://mysite` – This site runs under *Application Pool 1*.
6361
- An application *test2* under the root: `https://mysite/test2` – This application runs under *Application Pool 2*.
64-
- Your ASP.NET application runs under the *tes2* application with the following code:
62+
- Your ASP.NET application runs under the *test2* application with the following code:
6563

6664
```csharp
6765
public void Configuration(IAppBuilder app)
@@ -97,7 +95,7 @@ For example, suppose you have the following environment:
9795
}
9896
```
9997

100-
And you are using the following code for triggering the sign in flow:
98+
You use the following code to trigger the sign-in flow:
10199

102100
```csharp
103101
public void SignIn()
@@ -111,7 +109,7 @@ For example, suppose you have the following environment:
111109
}
112110
```
113111

114-
This scenario can result in an authentication infinite loop with a build-up of multiple OpenIdConnect.nonce cookies. The difference is that ASP.NET doesn't appear to set its authenticated session cookies. To resolve the issue in such scenario, set the redirect URLs in the OpenID Connect initialization code and the `Challenge` method (note the trailing slash in the redirect URL):
112+
This scenario can result in an authentication infinite loop with a buildup of multiple OpenIdConnect.nonce cookies. The difference is that ASP.NET doesn't appear to set its authenticated session cookies. To resolve the issue in such scenario, set the redirect URLs in the OpenID Connect initialization code and the `Challenge` method (note the trailing slash in the redirect URL):
115113

116114
```csharp
117115
app.UseOpenIdConnectAuthentication(
@@ -143,4 +141,4 @@ app.UseOpenIdConnectAuthentication(
143141

144142
[Infinite redirects with ASP.NET OWIN and OpenID Connect](https://varnerin.info/infinite-redirects-with-aspnet-owin-and-openid-connect/)
145143
146-
[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)]
144+
[!INCLUDE [Azure Help Support](../../../includes/azure-help-support.md)]

0 commit comments

Comments
 (0)