I want X-Frame-Options using c#. For this I am creating like the following.
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(System.Uri.UnescapeDataString(url));
string frameSupport = string.Empty;
using (WebResponse webResponse = request.GetResponse())
frameSupport = webResponse.Headers["X-Frame-Options"];
But when I pass url without http or https, I am getting the following issue.
Unable to cast object of type 'System.Net.FileWebRequest' to type 'System.Net.HttpWebRequest'.
WebRequestsupposed whether it's a file, ftp, http or https request? Why are you using an invalid URL in the first place?HttpWebRequest.Createmethod. This is a factory method defined on WebRequest. The compiler generates a warning and Visual Studio adds squigglies when you try to call a base static method like thishttps:.