|
thanks, I see,
but do you know
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
gives also IP? or sth else?
thank you again!!
your article is great!!
|
|
|
|
|
This will give Host IP where your application is deployed. But you are looking for visitor/Client IP.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
really? if so, I am confused by this code.
thanks again!
|
|
|
|
|
Yes
Now your next job is to find the country name.
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Seraph_summer wrote: your article is great!!
At least the Database provided in the article is the most important part of it. Its a great one indeed.
|
|
|
|
|
Client IP could be found from
ip=Request.ServerVariables("HTTP_X_FORWARDED_FOR");
if(ip==string.Empty)
{
ip=Request.ServerVariables("REMOTE_ADDR");
}
|
|
|
|
|
Hi, thanks!
I tried this code on my own PC, it shows the IP: 127.0.0.1
this is obviouly not right. This is not the right IP of my computer.
I saw from internet, there are also others have the same problem. then some people suggest using the following code:
string strHostName = System.Net.Dns.GetHostName();
string clientIPAddress = System.Net.Dns.GetHostAddresses(strHostName).GetValue(0).ToString();
but it shows the result as follows:
fe70::8c3:258f:3f47:fd6b%12
this is IP??
do you have more comments on this?
thank you again!!
|
|
|
|
|
|
|
If the user is behind a proxy then REMOTE_ADDR will be the proxy IP address and HTTP_X_FORWARDED_FOR will be the client IP address. HTTP_X_FORWARDED_FOR can consist of multiple comma separated IP addresses for each proxy the request passes through. Generally, client IP is the first of them.
Finally, you can rely on the above methods only for Transparent proxies. There is no way to trace the actual IP in case of Anonymous or Distorting proxies.
One more good tool for finding country from an IP is this one[^] on codeplex.
|
|
|
|
|
Please Help ,I have 3 day for my presentation in university just
I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
I use VS2008(C#) without service pack.PLZ Hlp
|
|
|
|
|
morteza451 wrote: I put a Login Name control into My pages but it show my page name.I am sure User Log in because Login Status Control show LoggedIN template but LoginName Can't show how user login.
Can you please give us the code block ?
If you want to know more about these controls, please read this
ASP.NET Login Controls Overview[^]
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
Hello everyone,
I am using Windows Server 2003 + VSTS 2008 + .Net 3.5 + C# + ASP.Net + IIS 6.0. I host some files (wmv video file and html file) on the web server, I want to know whether there are any easy to use authentication approach to let user input username and password before they can access (I want to prevent anonymous access)? Since the web site has also aspx ASP.Net page, and I want to use an unified authentication solution for wmv, html and aspx page. If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
Any ideas?
thanks in advance,
George
|
|
|
|
|
Hey George,
I am seeing ur question after a long time. How are u doing ?
George_George wrote: If prefer any solution which utilizes username and password stored in SQL Server database which my application already has/use.
So what is the problem with that ? why you are not authenticate the user from SQL Server itself . maintin session for giving the proper access of the page. or you can implement Roles for that !
Abhijit Jana | Codeproject MVP
Web Site : abhijitjana.net
Don't forget to click "Good Answer" on the post(s) that helped you.
|
|
|
|
|
I am fine, thank! Any ideas to my question?
|
|
|
|
|
in my asp page i have a text box and i want add a text and newline and text again repeatedly.
i uase txt1.text +="hello"+Environment.NewLine ;
but the newline is not working. any idea why ?
|
|
|
|
|
Because you've not set the control to be multiline. It's a property on the control.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
thanx . it's the textmode = multiline ;
|
|
|
|
|
Anyone got a link to a good tutorial which shows how to create a read-only text-box in a Web Application which automatically collects a visitor's IP Address?
Thanks
|
|
|
|
|
It's in the Request object ( the IP address ). Use a label, that's read only.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Why was this reply voted one?
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
Because, he did not give him the complete code snippet.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Here you go...
txtbox.Text = Request.ServerVariables["REMOTE_HOST"];
txtbox.Attribures.Add("readonly", "readonly");
.
|
|
|
|
|
public static string GetLocalAddress()
{
IPAddress[] addressLocal = Dns.GetHostByName(Dns.GetHostName()).AddressList;
if (addressLocal.Length > 0)
{
return addressLocal[addressLocal.Length - 1].ToString();
}
return "127.0.0.1";
}
|
|
|
|
|
This would always give the server address.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|