<p>I have a site, which contains several ashx handlers, on a couple of the handlers I want to reject non-SSL requests. Is there a way that I can do this in code?</p>

[{'answer_id': 59011, 'author': 'Kilhoffer', 'author_id': 5469, 'author_profile': 'https://Stackoverflow.com/users/5469', 'pm_score': 4, 'selected': True, 'text': '<p>If you must do it programmatically, a way I\'ve done it in the past is to inspect the url and look for "https" in it. Redirect if you don\'t see that. Request.IsSecureConnection should be the preferred method, however. You may have to add additional logic to handle a loopback address.</p>\n'}, {'answer_id': 59024, 'author': 'rpetrich', 'author_id': 4007, 'author_profile': 'https://Stackoverflow.com/users/4007', 'pm_score': 2, 'selected': False, 'text': "<p>I think the proper way is to check the Request.IsSecureConnection property and redirect or throw if it's false</p>\n"}, {'answer_id': 59026, 'author': 'Thunder3', 'author_id': 2832, 'author_profile': 'https://Stackoverflow.com/users/2832', 'pm_score': 2, 'selected': False, 'text': '<p>Try using the System.Web.HttpContext.Current.Request.IsSecureConnection to validate whether they are connecting securely, and then perform whatever denies you would like after that (returning an error message, or whatever your business need is).</p>\n'}]
['https://Stackoverflow.com/questions/59000', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5160/']