2016-09-07 16 views
0

私は訪問者を追跡するために必要なシンプルなWebアプリケーションを持っています。各訪問者の情報は、次の表に格納されます。ASP.NET Webアプリケーション訪問者カウンタ

VisitorsDetails:

| ID | ComputerName | VisitDate | CountryCode | Platform | Browser | BrowserVersion | 

[ComputerName]をvistorのIPアドレスです。

テーブルにはipv6レコードが含まれているため、訪問者数の計算に問題が発生したり、トークンエラーが発生することがあります。

訪問者にipv4を強制的に使用させることは賢明ですか? はいの場合、どうですか?

答えて

0
public string IpAddress() 
{ 
string strIpAddress; 
strIpAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 
if (strIpAddress == null) 
{ 
strIpAddress = Request.ServerVariables["REMOTE_ADDR"]; 
} 
return strIpAddress; 
} 

foreach (IPAddress IPA in Dns.GetHostAddresses(Dns.GetHostName())) 
{ 
if (IPA.AddressFamily.ToString() == "InterNetwork") 
{ 
IP4Address = IPA.ToString(); 
break; 
} 
} 

も以下のリンクをご参照ください:

http://www.4guysfromrolla.com/articles/071807-1.aspx http://tutorialgenius.blogspot.in/2010/09/aspnet-get-ipv4-address-even-if-user-is.html

+0

ありがとう、これは私が探していたものです。 –

0
void Application_Start(object sender, EventArgs e) 
{ 
    // Code that runs on application startup 
    Application["NoOfVisitors"] = 0; 
} 





void Session_Start(object sender, EventArgs e) 
{ 
    // Code that runs when a new session is started 
    Application.Lock(); 
    Application["NoOfVisitors"] = (int)Application["NoOfVisitors"] + 1; 
    Application.UnLock(); 
} 

in .aspx page 

<asp:Label runat="server" ID="lbluser" /> 
in .aspx.cs 

protected void Page_Load(object sender, EventArgs e) 
{ 
    lbluser.Text = Application["NoOfVisitors"].ToString(); 
} 
+0

ニース、しかし、大きな問題は、HTTP_X_FORWARDED_FORが複数の値を返すことは可能である –

0
protected void Application_Start() 
    { 
     AreaRegistration.RegisterAllAreas(); 
     RegisterRoutes(RouteTable.Routes); 

     WebpageCounter.SaveVisitor(new WebpageVisitor() 
     { 
      VisitorIP = HttpContext.Current.Request.UserHostAddress, 
      VisitedOn = DateTime.Now 
     }); 
    } 
------------- 
Below Code is for IP Address 
string ipaddress; 
ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 
if (ipaddress == "" || ipaddress == null) 
    ipaddress = Request.ServerVariables["REMOTE_ADDR"]; 
+0

をIPV6ています。どのように私はipv4のみを取得することを確認します –

関連する問題