Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Out if ASP.NET Request Came From Local Machine

I've built an ASP.NET application that's using Forms Authentication. In our hosting account control panel, I set up an automated task that requests a web page once per week. When the page loads, a number of emails are sent out.

I'd just like to know if there's any way to determine in the code-behind if the request is coming from the local machine (as with Windows authentication). Using a separate web.config file in the page sub-directory with Windows authentication mode doesn't work.

The application will work fine either way. I'm requiring that a specific Guid value be present in the query string, so it's very unlikely that the task will be executed by mistake. I'd just like to learn something new while I'm working on this, and I'd like to see if I can add this little bit of extra verification.

Thanks very much for any advice.

like image 453
Aaron Drenberg Avatar asked Jul 18 '10 15:07

Aaron Drenberg


2 Answers

Request.IsLocal

The IsLocal property returns true if the IP address of the request originator is 127.0.0.1 or if the IP address of the request is the same as the server's IP address.

like image 75
Pete Montgomery Avatar answered Sep 26 '22 04:09

Pete Montgomery


Request.Url.IsLoopback
like image 45
Darin Dimitrov Avatar answered Sep 25 '22 04:09

Darin Dimitrov