-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Behavior is different to what is documented - IFormCollection.Item[String] Property #36712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can read form fields in a get request. It seems you're trying to replace the indexer which merged query and form I believe. That doesn't exist in ASP.NET Core. If you want to read the query string then use .Query and if you need to read the form you can use .Form but only when a form is actually being posted. |
Ahh, I see, OK so the entire scenario is invalid here, OK that makes sense this test is a bit contrived. May I ask then, in old .NetF code we have this: string tmpAuthIdentity = System.Web.HttpContext.Current.Request["LOGON_USER"]; I want to simply replace this with whatever is equivalent under ASP.NET Core, may articles talk about this being a server variable in older .NetF apps. So I don't know that this is anything in a form this was just an experiment (and we did not expect an exception). The old ASP.NET documentation describes the indexer thus:
It doesn't make it clear if a key could be present in each and if so, in what order it searches each of these. The above .NetF code works fine, its part of a larger library we've had for years, I'm just trying to tweak the few areas of the code that are not compatible with .NetF. Thanks for your prompt reply by the way @davidfowl |
By the way, if the access to |
Seems like you're looking to read the server variables. This will only work on IIS. There's likely a modern alternative to this that doesn't require looking at this value. You should be able to do this: string tmpAuthIdentity = NepHttpContext.Curent.GetServerVariable("LOGON_USER"); The modern alternative though is likely: string tmpAuthIdentity = NepHttpContext.Current.User.Identity.Name; |
Triage: |
Thanks for contacting us. We're moving this issue to the |
Fixes #36712 Co-authored-by: Safia Abdalla <[email protected]> Co-authored-by: James Newton-King <[email protected]>
Describe the bug
When porting old .NetF code we had to make changes because Request no longer has an indexer but instead exposes sub-properties that themselves have indexers.
During a test we attempt this:
The code throws an exception yet it should either return the value or return
StringValues.Empty
or throw if the supplied key is null - according to the documentation.Its seems that either the documentation is wrong or this is a bug.
To Reproduce
Just create a new empty .Net5 web app and then add the above code to the template code that's present in the project, as shown here:
The
NepHttpContext
class is our own helper class, it just gets the current request.Exceptions (if any)
Further technical details
dotnet --info
App targets .Net5, using VS 2019, here's the donet info:
The text was updated successfully, but these errors were encountered: