Home » Development » Solution for 417 Expectation Failed error and Expect header issues

Solution for 417 Expectation Failed error and Expect header issues

Your web application may show a custom error like this: “You are not authorized to access this portal”. Most of the time, custom errors are static and therefore, they may mislead. For the same issue, I saw “417 Expectation Failed” error in the F12 Developer Tools network trace.

417 status code refers to an issue with the Expect header in the request. The server was probably not able to meet the requirement in this header (RFC7231).

417 Expectation Failed error

Solution for “417 Expectation Failed”

I recommend collecting a Fiddler trace and analyzing the header. As always, doing due diligence like probing when the issue started occurring, what was changed, does it work in another server, etc. helps as well.

In my case, the root cause was a missing forward slash character (“/”) at the end of the CorsOrigin parameter in appsettings.json. After adding this, the application started working.

Note: System.Net.HttpWebRequest adds “Expect: 100-Continue”‘ to requests (Reference). You may try removing it explicitly to solve this issue:

System.Net.ServicePointManager.Expect100Continue = false;

Another way to remove this header is to change web.config configuration:

        <servicePointManager expect100Continue="false" />

Ned Sahin

Blogger for 20 years. Former Microsoft Engineer. Author of six books. I love creating helpful content and sharing with the world. Reach me out for any questions or feedback.

Leave a Comment