Request.IsLocal alternative?

As far as I understand, Request.IsLocal returns true in two scenarios. If the IP address of the request sender is 127.0.0.1 or if the IP address of the request matches the IP address of the server.

I use this on a page that is regularly called by the cron task (using an absolute URL). Unfortunately, this cron job runs on the same server as the page, which means that IsLocal always returns true.

Ideally, I need a function that just returns true if I am on a local host. How to do it in ASP.NET MVC?

+4
source share
1 answer

You can look at the Request.Url property in MVC, but you need to check at least 127.0.0.1, localhost and :: 1. There can also be quite a lot to do with UrlRewrite if all you want to do is access to requests. You are not saying what you want to do if it returns true / false, but on the condition that one of the things you want to do is take a look at UrlRewrite. This post also has tons of useful information;

How to restrict access to the page only to the local host?

0
source

Source: https://habr.com/ru/post/1439924/


All Articles