Request.IsLocal alternative?

2019-04-10 05:59发布

As far as I understand, Request.IsLocal returns true in two scenarios. 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.

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

Ideally, I need a function which will just return true if I'm on localhost. How can I do this in a ASP.NET MVC environment?

1条回答
走好不送
2楼-- · 2019-04-10 06:45

You could look at the Request.Url property in MVC, but you need to check for 127.0.0.1, localhost and ::1 at least. There's also quite a lot you can do with UrlRewrite if all you want to do is request access. You don't say what you want to do if it returns true/false but assuming that's one of the things you want to do, have a look at UrlRewrite. There's a bunch of useful information in this post too;

How to limit page access only to localhost?

查看更多
登录 后发表回答