Request.IsLocal替代吗? [英] Request.IsLocal alternative?

查看:75
本文介绍了Request.IsLocal替代吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解, Request.IsLocal 在两种情况下返回true.如果请求发起者的IP地址是127.0.0.1,或者请求的IP地址与服务器的IP地址相同.

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.

我在cron任务(使用绝对URL)定期调用的页面上使用此功能.不幸的是,此cron作业与页面在同一服务器上运行,这意味着IsLocal始终返回true.

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.

理想情况下,如果我在本地主机上,我需要一个将 just 返回true的函数.如何在ASP.NET MVC环境中做到这一点?

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?

推荐答案

您可以查看MVC中的Request.Url属性,但是至少需要检查127.0.0.1,localhost和:: 1.如果您要做的只是请求访问,那么使用UrlRewrite也可以做很多事情.您不会说返回true/false时要做什么,但是假设这是您要做的事情之一,请查看UrlRewrite.这篇文章中也有很多有用的信息;

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;

如何将页面访问限制为仅对localhost?

这篇关于Request.IsLocal替代吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆