Solution for the QlikView, Biztalk, DotNet and MSBI real time development problems
Search This Blog
Monday, September 26, 2011
How to get the users IP those who are accessing your website using asp.net
Use below code to get the IP of your website users:
<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Client IP...</title>
<meta http-equiv="Expires" content="-1">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<%
string _strClientIP = string.Empty;
string[] _strforwardedIpsList;
// Get exact IP address if proxy available
string _strServerVariable = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(_strServerVariable))
{
_strforwardedIpsList = _strServerVariable.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
_strClientIP = _strforwardedIpsList[_strforwardedIpsList.Length - 1];
}
else
{
// Get Proxy IP address
_strClientIP = HttpContext.Current.Request.UserHostAddress;
if (string.IsNullOrEmpty(_strClientIP))
_strClientIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
Response.Write(_strClientIP);
%>
</head>
<body>
<form id="testForm">
</form>
</body>
</html>
Labels:
ASP.NET
Subscribe to:
Post Comments (Atom)
Popular Posts
-
What is SQL Injection SQL Injection is one of the most dangerous possible attacks we have to deal with as a web application developer, a...
-
Qlikview developer, Designer and admin interview questions (Qlikview developer, Designer and admin FAQ’S) 1. Difference between Set ...
-
For MVC Interview Questions Part 2 refer below link: http://challadotnetfaq.blogspot.co.uk/2013/12/mvc-interview-questions-and-answers_...
-
. Following code is useful to delete duplicate records. The table must have identity column, which will be used to identify the duplicate re...
-
/*If you are facing issues with saving large data into excel * u may get oledbexception like * "The field is too small to accept th...
1 comment:
Play at the best online casinos for US players
The Best Online Casinos for US Players · Red Dog Casino: $10 Free + up to $250 · 888 Casino: $25 Free + $300 Deposit Bonus · Ignition Casino: $1000 Match 카지노사이트luckclub
Post a Comment