You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote
135
+
- Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote
133
136
login. ---> System.InvalidOperationException: An invalid request URI was provided. Either the request URI must be an
134
137
absolute URI or BaseAddress must be set.
135
138
136
139
### Diagnosing
137
140
138
-
Run this command in powershell:
141
+
Run this command in PowerShell:
139
142
140
-
```bash
143
+
```powershell
141
144
dotnet list package --include-transitive | sls "Microsoft.IdentityModel|System.IdentityModel"
142
145
```
143
146
@@ -153,7 +156,7 @@ The output should look something like this:
153
156
> System.IdentityModel.Tokens.Jwt 7.0.3
154
157
```
155
158
156
-
In the above example it is clear that there are different versions active.
159
+
In the example above, it is clear that there are different versions active.
157
160
158
161
### Fixing
159
162
@@ -173,7 +176,7 @@ version used.
173
176
In some installations, upgrading .NET and IdentityServer has caused performance issues. Since the IdentityServer and
174
177
.NET version upgrades typically are done at the same time, it is sometimes hard to tell what the root cause is
175
178
for the performance degradation. When working with installations to find the root cause, there are some dependencies
176
-
that have been found to cause issues in specific verisons.
179
+
that have been found to cause issues in specific versions.
177
180
178
181
### PostgreSQL Pooling
179
182
@@ -204,13 +207,13 @@ and possible mitigations.
204
207
205
208
The `Azure.Core` package versions `1.41.0` and prior had an issue that caused delays when accessing Azure resources.
206
209
This could be Azure blob storage or key vault for data protection or Azure SQL Server for stores, especially if managed
207
-
identities are used. This package is typically not referenced directly but brought in as a transient dependency
210
+
identities are used. This package is typically not referenced directly but brought in as a transient dependency
208
211
through other packages. Ensure to use version `1.42.0` or later if you are hosting on Azure.
209
212
210
213
### Entity Framework Core, Microsoft.Data.SqlClient, and SqlServerRetryingExecutionStrategy
211
214
212
215
As more developers migrate their database-powered application to the cloud,
213
-
they will need to handle intermittent connection failures. In most cases, these transient connection failures occur and resolve in a short period of time, allowing the application to self-correct and continue processing requests. The strategy is known as **connection resiliency**.
216
+
they will need to handle intermittent connection failures. In most cases, these transient connection failures occur and resolve in a short period of time, allowing the application to self-correct and continue processing requests. The strategy is known as **connection resiliency**.
214
217
215
218
In recent versions of Entity Framework Core and `Microsoft.Data.SqlClient`, you can enable this retry strategy explicitly, but in the case of `Microsoft.Data.SqlClient`, when operating in a cloud environment, this strategy is enabled by default or defined in the connection string.
216
219
@@ -229,8 +232,8 @@ In most cases, this is a _good feature to have enabled_ but there are drawbacks
229
232
- Enabling retry on failure causes Entity Framework Core to buffer the result set. This significantly increases memory requirements and causes garbage collection pauses.
230
233
- Some versions of `Microsoft.Data.SqlClient` call `Thread.Sleep` that can lock threads for up to **_10 seconds_**. This can lead to thread exhaustion and server unresponsiveness. We've isolated this issue to versions.
231
234
232
-
| Microsoft.EntityFrameworkCore.SqlServer | Microsoft.Data.SqlClient | Status |
@@ -269,6 +272,86 @@ When dealing with external authentication, you may want to set `MapInboundClaims
269
272
270
273
When dealing with external authentication, you may want to implement `OnTicketReceived` to reduce the size of the cookie. This is a callback that is invoked after the external authentication process is complete. You can use this callback to remove any claims that are not needed by your solution.
271
274
275
+
## URL and Query String Size Limits and Management
276
+
277
+
While most browsers currently support URLs longer than 2000 characters, web servers may still return an error status code
278
+
when they find that the URL or query string is too long.
279
+
280
+
For most authentication flows, URLs will stay well under 2000 characters in length. When federating to an external
281
+
identity provider, however, URLs can quickly grow too large because of all the query parameters that were added.
282
+
283
+
Web servers can respond differently when a URL or query string is too large:
284
+
285
+
- Apache responds with `414 Request-URI Too Large` when a URL exceeds 8190 bytes.
286
+
- IIS responds with `404 Not Found` and uses two different substatus codes depending on the issue:
287
+
- If the URL exceeds 4096 bytes, the substatus code is `404.14 URL Too Long`.
288
+
- If the query string exceeds 2048 bytes, the substatus code is `404.15 Query String Too Long`.
289
+
- Nginx responds with `414 Request-URI Too Large` when a URL exceeds 8192 bytes.
290
+
291
+
To fix this issue, there are two solutions:
292
+
293
+
### Reduce State Query Parameter Size
294
+
295
+
When IdentityServer redirects the user to an external Identity Provider, it includes a data protected `state` query parameter.
296
+
The combination of this `state` parameter with other data being added by the external IdP can cause the URL to become too large.
297
+
You can drastically reduce the size of the `state` parameter by storing the state in IdentityServer, rather than passing it along
298
+
in the request URL.
299
+
300
+
See [External Providers - State, URL length, And ISecureDataFormat](/identityserver/ui/login/external/#state-url-length-and-isecuredataformat)
301
+
for more information about this workaround.
302
+
303
+
### Increase the Maximum Size of URL or Query String data
304
+
305
+
Depending on the web server you're using, you can change the maximum size of the URL or query string.
306
+
307
+
:::caution
308
+
While increasing the size limits may work for your use case, the first solution is a more robust way to reduce the size
309
+
of the query string when federating with an external identity provider.
310
+
:::
311
+
312
+
{/* prettier-ignore */}
313
+
<Tabs>
314
+
<TabItemlabel="Apache">
315
+
You can increase the value for `LimitRequestLine` to allow longer URLs, by adding or changing this directive in your
316
+
server config file (for all virtual hosts), or for specific virtual hosts in their respective `<VirtualHost></VirtualHost>` entry.
317
+
318
+
See https://httpd.apache.org/docs/2.4/mod/core.html#limitrequestline for more information.
319
+
320
+
</TabItem>
321
+
<TabItemlabel="Microsoft IIS">
322
+
Configure the `requestLimits` XML element to increase the max URL and query string size in your `web.config` file:
To fix this issue on Azure hosted web applications, add the following environment variable to the App Service:
384
+
301
385
```text
302
386
WEBSITE_LOAD_USER_PROFILE=1
303
387
```
304
388
305
389
After saving this environment variable, your App Service will restart and Kudu (the engine behind git deployments in Azure App Service)
306
390
will load the user profile when running your web application.
307
-
For more information about this and other Kudu configuration options, see https://github.com/projectkudu/kudu/wiki/Configurable-settings.
391
+
For more information about this and other Kudu configuration options, see https://github.com/projectkudu/kudu/wiki/Configurable-settings.
308
392
309
393
If you're hosting the web application using IIS on Windows, you'll need to configure the application pool to load the user profile. See https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/advanced?view=aspnetcore-9.0#data-protection
310
394
for more information on how to configure the application pool.
311
395
312
396
### Why does a web application need to load a user profile to work with X.509 certificates?
313
397
314
398
The `X509Certificate2` class in .NET stores the private key part of a certificate somewhere else depending on the use of `X509KeyStorageFlags`:
315
-
*`X509KeyStorageFlags.MachineKeySet` stores the private key in a `Keys` registry subfolder of the certificate store.
316
-
*`X509KeyStorageFlags.UserKeySet` stores the private key in the current user's roaming profile folder, e.g. `%AppData%\Microsoft\SystemCertificates\My\Keys`.
399
+
400
+
-`X509KeyStorageFlags.MachineKeySet` stores the private key in a `Keys` registry subfolder of the certificate store.
401
+
-`X509KeyStorageFlags.UserKeySet` stores the private key in the current user's roaming profile folder, e.g. `%AppData%\Microsoft\SystemCertificates\My\Keys`.
317
402
318
403
When loading a certificate containing both a public and private key in .NET, the private key may also end up in different locations:
319
-
* Machine keys end up in the `%ProgramData%\Microsoft\Crypto\RSA\MachineKeys` folder.
320
-
* User keys are stored in the current user's roaming profile folder but this time in a different location: `%AppData%\Microsoft\Crypto\RSA`
404
+
405
+
- Machine keys end up in the `%ProgramData%\Microsoft\Crypto\RSA\MachineKeys` folder.
406
+
- User keys are stored in the current user's roaming profile folder but this time in a different location: `%AppData%\Microsoft\Crypto\RSA`
321
407
322
408
If you don't explicitly use the `X509KeyStorageFlags.MachineKeySet` flag value, the default behavior is to use `X509KeyStorageFlags.DefaultKeySet`.
323
409
According to the [.NET documentation][1], this means: _The default key set is used. **The user key set is usually the default**_.
324
410
325
411
When an application runs without an active user profile, any private key material stored in a user profile can't be accessed.
326
412
Even loading a certificate can fail, since the load operation could attempt to store the private key material in the user profile.
0 commit comments