带C#.net的Asp.net [英] Asp.net with C#.net
问题描述
我正在将Windows应用程序与c#.net一起使用,我想获取系统ip地址并访问数据库
使用System.Text;
使用System.Windows.Forms;
使用System.Diagnostics;
.
.
.
字符串strClientIP;
字符串[] computer_name = System.Net.Dns.GetHostEntry(Process.ServerVariables ["remote_addr"]).HostName.Split(new Char [] {''.''}));
textBox1 .Text = strClientIP.ToString()+"[" + computer_name [0] .ToString()+]";
这是我的错误
System.Diagnostics.Process''不包含``ServerVariables''的定义如何解决此错误
I am using windows application with c#.net I want Get system ip address and strore the database
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
.
.
.
string strClientIP;
string[] computer_name = System.Net.Dns.GetHostEntry(Process.ServerVariables["remote_addr"]).HostName.Split(new Char[] { ''.'' });
textBox1 .Text = strClientIP.ToString() + "[" + computer_name[0].ToString() + "]";
This is i got error
System.Diagnostics.Process'' does not contain a definition for ''ServerVariables'' how to slove this error
推荐答案
ServerVariables
是dll.
在Windows应用程序中没有任何意义.
根据您的标签,我不确定这是Windows还是Web应用程序,但是如果它是Web应用程序,则添加对System.Web dll的引用.
ServerVariables
is a property of theSystem.Web
dll.
It makes no sense in a Windows Application.
Based on your tag I''m not sure if this is a windows or web application, but if it is a web one, add a reference to the System.Web dll.
尝试一下
要在C#中获取本地计算机的IP地址,
使用system.net名称空间
从IPHostEntry类,我们以字符串数组的形式获取列表.
Try this
To get the IP address of the local machine in C#,
using system.net namespace
From IPHostEntry class, we get the list in a string array.
using System.Net;
Private string GetIP()
{
string strHostName = "";
strHostName = System.Net.Dns.GetHostName();
IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
return addr[addr.Length-1].ToString();
}
谢谢
SP
Thanks
SP
这篇关于带C#.net的Asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!