Reputation: 1315
The following code throws and exception in dotnet 5 but does not in dotnet framework 4.8:
var req = (HttpWebRequest)HttpWebRequest.Create(urlIncludingScheme);
req.AllowAutoRedirect = false;
var resp = (HttpWebResponse)req.GetResponse()
In framework 4.8 a HttpWebResponse is returned with the StatusCode "Moved" In dotnet core an exception is thrown with the message "The remote server returned an error: (301) Moved Permanently."
This makes me a little nervous about porting stuff from 4.8 to dotnet 5. I would expect this behaviour to remain unchanged in dotnet 5.
Can anyone tell if this is a bug or if it is actually the entention?
This is also discussed here: Redirect of WebRequest in .NET Core
But there is not discussion of the reason behind this difference.
Also, the discussion here does not explain if it is really the intention to make a breaking change in this scenario: https://github.com/dotnet/runtime/issues/23264
This was also reported as a bug here and solved, but doesnt seem to have been fixed: https://github.com/dotnet/runtime/issues/1074
Upvotes: 1
Views: 1082
Reputation: 1315
It turns out that my project was running dotnet core 3.1.
framework 4.8: No exception
dotnet core 3.1: Exception thrown
dotnet 5: No exception - so the bug seems to have been fixed in dotnet 5.
I think it can be concluded that the exception was in fact unintended and has now been fixed.
Upvotes: 2