I have implemented ASP.Net application deployed in IIS with http and https port enabled. Now i have an requirement to reject the HTTP requests basis on Web.Config value. If this value set to True then it should not accept requests which are coming with HTTP like it should throw an error Invalid Operation.. Try requesting with Secure connection
. The first thing i did is to check this in Global.asax file as Below:
if (Utilities.Utility.HttpsCheck)
{
if (!Request.IsSecureConnection)
{
Response.Write("Invalid Operation");
}
}
In this method i got an exception request is not available in this context
. I googled it about this error and got to know that it can't be possible to access Request
in Global file in ASP.NET.
Next method I tried is to add this above code in every page of my project and checking this before going to process request. But by doing this way i can not have control of preventing request to HTML pages, i have some html pages also in my project these files also i need to restrict.
If I include code in Page wise then it is applying for that page only.. But i have some image/video files also in website these also needs to restrict.
Is there any better way out to do this? Please help me in this regard.
Thanks in Advance.