Skip to content

Commit a047a2c

Browse files
committed
Improve IFormCollection.Items documentation
Fixes #36712
1 parent d50b77b commit a047a2c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/Http/Http.Features/src/IFormCollection.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,24 @@ public interface IFormCollection : IEnumerable<KeyValuePair<string, StringValues
7777
/// <exception cref="System.ArgumentNullException">
7878
/// key is null.
7979
/// </exception>
80+
/// <exception cref="System.InvalidOperationException">
81+
/// incorrect content-type.
82+
/// </exception>
8083
/// <remarks>
84+
/// <para>
8185
/// <see cref="IFormCollection" /> has a different indexer contract than
8286
/// <see cref="IDictionary{TKey, TValue}" />, as it will return <c>StringValues.Empty</c> for missing entries
8387
/// rather than throwing an Exception.
88+
/// </para>
89+
/// <para>
90+
/// This indexer can only be used on POST requests. Otherwise an exception of type
91+
/// <see cref="System.InvalidOperationException" /> is thrown.
92+
/// </para>
93+
/// <para>
94+
/// Invoking this property could result in thread exhaustion since it's wrapping an asynchronous implementation.
95+
/// To prevent this the method <see cref="Microsoft.AspNetCore.Http.Features.FormFeature.ReadFormAsync"> can be used.
96+
/// For more information please read https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/.
97+
/// </para>
8498
/// </remarks>
8599
StringValues this[string key] { get; }
86100

src/Http/Http/src/Features/FormFeature.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ public IFormCollection ReadForm()
101101

102102
if (!HasFormContentType)
103103
{
104-
throw new InvalidOperationException("Incorrect Content-Type: " + _request.ContentType);
104+
throw new InvalidOperationException("Form Collection properties can only be accessed from a POST request");
105105
}
106106

107-
// TODO: Issue #456 Avoid Sync-over-Async http://blogs.msdn.com/b/pfxteam/archive/2012/04/13/10293638.aspx
107+
// TODO: Issue #456 Avoid Sync-over-Async https://devblogs.microsoft.com/pfxteam/should-i-expose-synchronous-wrappers-for-asynchronous-methods/
108108
// TODO: How do we prevent thread exhaustion?
109109
return ReadFormAsync().GetAwaiter().GetResult();
110110
}

0 commit comments

Comments
 (0)