Can I fool HttpRequest.Current.Request.IsLocal?

前端 未结 4 1767
-上瘾入骨i
-上瘾入骨i 2021-02-08 07:44

I\'m running a web application that displays some debugging behavior if it\'s being run locally - quotes around resource strings, etc - and I\'d like to demo the application on

4条回答
  •  [愿得一人]
    2021-02-08 08:24

    Request.IsLocal property implements the following code :

    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;
                } 
    

    Source : Decompiled source code (Microsoft : referencesource.microsoft.com )

    Hope this helps !

提交回复
热议问题