如何仅打开特定IP地址的网页 [英] How to Open Web Page for Particular IP Address Only

查看:109
本文介绍了如何仅打开特定IP地址的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨frnds ..



我想知道,我们是否可以在web.config中定义任何设置,以便从特定提到的特定webPage中打开仅限IpAddress。



当用户尝试从其他IpAddress打开网页时,我们应该阻止他们访问该页面。



我的想法是我可以在PageLoad中查看,但我想知道,如何在没有编码的情况下做到这一点..



谢谢提前

Sameer

解决方案

试试这个代码



 受保护  void  GetUser_IP()
{
string VisitorsIPAddr = string .Empty;
if (HttpContext.Current.Request.ServerVariables [ HTTP_X_FORWARDED_FOR]!= null
{
VisitorsIPAddr = HttpContext.Current.Request.ServerVariables [ HTTP_X_FORWARDED_FOR]。ToString();
}
else if (HttpContext.Current.Request.UserHostAddress.Length! = 0
{
VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
}

.UserIPAddress = VisitorsIPAddr;
}





这将为您提供当前用户的IP。因此您可以在页面上验证重新划分的用户负荷。


Hi frnds..

I want to know, whether we can define any setting in web.config so that the particular webPage should be opened from the particular mentioned IpAddress only.

When user trying to Open the webpage from other IpAddress, then we should stop them to access the page.

The idea i have is I can check that in PageLoad, but i want to know , how to do that without coding..

Thanks in Advance
Sameer

解决方案

try this code

protected void GetUser_IP()
  {
      string VisitorsIPAddr = string.Empty;
      if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
      {
          VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
      }
      else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
      {
          VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
      }

      this.UserIPAddress = VisitorsIPAddr;
  }



this will get you the current users's IP.so you can validate the redistricted users on page load.


这篇关于如何仅打开特定IP地址的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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