gpt4 book ai didi

asp.net - 我可以欺骗 HttpRequest.Current.Request.IsLocal 吗?

转载 作者:行者123 更新时间:2023-12-02 11:54:08 25 4
gpt4 key购买 nike

我正在运行一个 Web 应用程序,如果它在本地运行,它会显示一些调试行为 - 资源字符串周围的引号等 - 并且我想在没有互联网的 session 上在我的笔记本电脑上演示该应用程序访问,因此它必须是本地的。

应用程序使用 HttpContext.Current.Request.IsLocal 来确定它是否在本地运行 - 有什么方法可以欺骗它吗?我想欺骗它返回“False”,即使我确实在本地运行。

我确实可以访问源代码(并意识到我可以演示一个注释掉“IsLocal”检查的构建),但不想为此演示进行特殊构建。如果需要,我会这样做,但我宁愿不受影响地使用现有的代码库。

最佳答案

Request.IsLocal 属性实现以下代码:

public bool IsLocal { 
get {
String remoteAddress = UserHostAddress;

// if unknown, assume not local
if (String.IsNullOrEmpty(remoteAddress))
return false;

// check if localhost
if (remoteAddress == "127.0.0.1" || remoteAddress == "::1")
return true;

// compare with local address
if (remoteAddress == LocalAddress)
return true;

return false;
}

来源:反编译源代码(Microsoft:referencesource.microsoft.com)

希望这有帮助!

关于asp.net - 我可以欺骗 HttpRequest.Current.Request.IsLocal 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/680079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com