using System;
using System.Collections.Generic;
using System.Text;
namespace 智承科技
{
class SqlLocator
{
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
public static extern short SQLAllocHandle(short hType, IntPtr inputHandle, out IntPtr outputHandle);
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
public static extern short SQLSetEnvAttr(IntPtr henv, int attribute, IntPtr valuePtr, int strLength);
[System.Runtime.InteropServices.DllImport("odbc32.dll")]
public static extern short SQLFreeHandle(short hType, IntPtr handle);
[System.Runtime.InteropServices.DllImport("odbc32.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi)]
public static extern short SQLBrowseConnect(IntPtr hconn, System.Text.StringBuilder inString,
short inStringLength, System.Text.StringBuilder outString, short outStringLength,
out short outLengthNeeded);
public const short SQL_HANDLE_ENV = 1;
public const short SQL_HANDLE_DBC = 2;
public const int SQL_ATTR_ODBC_VERSION = 200;
public const int SQL_OV_ODBC3 = 3;
public const short SQL_SUCCESS = 0;
public const short SQL_NEED_DATA = 99;
public const short DEFAULT_RESULT_SIZE = 1024;
public const string SQL_DRIVER_STR = "DRIVER=SQL SERVER";
public SqlLocator() { }
public static string[] GetServers()
{
string list = string.Empty;
IntPtr henv = IntPtr.Zero;
IntPtr hconn = IntPtr.Zero;
System.Text.StringBuilder inString = new System.Text.StringBuilder(SQL_DRIVER_STR);
System.Text.StringBuilder outString = new System.Text.StringBuilder(DEFAULT_RESULT_SIZE);
short inStringLength = (short)inString.Length;
short lenNeeded = 0;
try
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_ENV, henv, out henv))
{
if (SQL_SUCCESS == SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (IntPtr)SQL_OV_ODBC3, 0))
{
if (SQL_SUCCESS == SQLAllocHandle(SQL_HANDLE_DBC, henv, out hconn))
{
if (SQL_NEED_DATA == SQLBrowseConnect(hconn, inString, inStringLength, outString,
DEFAULT_RESULT_SIZE, out lenNeeded))
{
if (DEFAULT_RESULT_SIZE < lenNeeded)
{
outString.Capacity = lenNeeded;
if (SQL_NEED_DATA != SQLBrowseConnect(hconn, inString, inStringLength, outString,
lenNeeded, out lenNeeded))
{
throw new ApplicationException("Unabled to aquire SQL Servers from ODBC driver.");
}
}
list = outString.ToString();
int start = list.IndexOf("{") + 1;
int len = list.IndexOf("}") - start;
if ((start > 0) && (len > 0))
{
list = list.Substring(start, len);
}
else
{
list = string.Empty;
}
}
}
}
}
}
catch
{
list = string.Empty;
}
finally
{
if (hconn != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_DBC, hconn);
}
if (henv != IntPtr.Zero)
{
SQLFreeHandle(SQL_HANDLE_ENV, hconn);
}
}
string[] array = null;
if (list.Length > 0)
{
array = list.Split(',');
}
return array;
}
}
}
我做的
2、ASP.NET(C#)怎么获得当前域名?
HttpContext.Current.Request.Url.Host.ToString()
3、asp。net,如果用户直接输入网址,如何获取网址对其做处理后在显示页面?(我的问题是如何先获取网址)
通过ASP.NET获取 如果测试的url地址是 http://www.test.com/testweb/default.aspx, 结果如下: Request.ApplicationPath: /testweb Request.CurrentExecutionFilePath: /testweb/default.aspx Request.FilePath: /testweb/default.aspx Request.Path: /testweb/default.aspx Request.PhysicalApplicationPath: E:\WWW\testwebRequest.PhysicalPath: E:\WWW\testweb\default.aspx Request.RawUrl: /testweb/default.aspx Request.Url.AbsolutePath: /testweb/default.aspx Request.Url.AbsoluteUrl: http://www.test.com/testweb/default.aspx Request.Url.Host: www.test.com Request.Url.LocalPath: /testweb/default.aspx 2、通过JS获取 <table width=100% cellpadding=0 cellspacing=0 border=0 > <script> thisURL = document.URL; thisHREF = document.location.href; thisSLoc = self.location.href; thisDLoc = document.location; strwrite = "<tr><td valign=top>thisURL: </td><td>[" + thisURL + "]</td></tr>" strwrite += "<tr><td valign=top>thisHREF: </td><td>[" + thisHREF + "]</td></tr>" strwrite += "<tr><td valign=top>thisSLoc: </td><td>[" + thisSLoc + "]</td></tr>" strwrite += "<tr><td valign=top>thisDLoc: </td><td>[" + thisDLoc + "]</td></tr>" document.write( strwrite ); </script> thisDLoc = document.location; <BR> thisURL = document.URL; <BR> thisHREF = document.location.href; <BR> thisSLoc = self.location.href;<BR> <script> thisTLoc = top.location.href; thisPLoc = parent.document.location; thisTHost = top.location.hostname; thisHost = location.hostname; strwrite = "<tr><td valign=top>thisTLoc: </td><td>[" + thisTLoc + "]</td></tr>" strwrite += "<tr><td valign=top>thisPLoc: </td><td>[" + thisPLoc + "]</td></tr>" strwrite += "<tr><td valign=top>thisTHost: </td><td>[" + thisTHost + "]</td></tr>" strwrite += "<tr><td valign=top>thisHost: </td><td>[" + thisHost + "]</td></tr>" document.write( strwrite ); </script> thisTLoc = top.location.href; <BR> thisPLoc = parent.document.location; <BR> thisTHost = top.location.hostname; <BR> thisHost = location.hostname;<BR> <script> tmpHPage = thisHREF.split( "/" ); thisHPage = tmpHPage[ tmpHPage.length-1 ]; tmpUPage = thisURL.split( "/" ); thisUPage = tmpUPage[ tmpUPage.length-1 ]; strwrite = "<tr><td valign=top>thisHPage: </td><td>[" + thisHPage + "]</td></tr>" strwrite += "<tr><td valign=top>thisUPage: </td><td>[" + thisUPage + "]</td></tr>" document.write( strwrite ); </script><tr><td> ================= 获取IP 1、ASP.NET中获取 获取服务器的IP地址: using System.Net; string myIP,myMac; System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; if ( addressList.Length>1) { myIP = addressList[0].ToString(); myMac = addressList[1].ToString(); } else { myIP = addressList[0].ToString(); myMac = "没有可用的连接"; } myIP地址就是服务器端的ip地址。 获取客户端的ip地址,可以使用 //获取登录者ip地址 string ip = Request.ServerVariables["REMOTE_ADDR"].ToString(); 2、通过JS获取 <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=gbk"> </head> <body> <object classid="CLSID:76A64158-CB41-11D1-8B02-00600806D9B6" id="locator" style="display:none;visibility:hidden"></object> <object classid="CLSID:75718C9A-F029-11d1-A1AC-00C04FB6C223" id="foo" style="display:none;visibility:hidden"></object> <form name="myForm"> <br/>MAC地址:<input type="text" name="macAddress"> <br/>IP地址:<input type="text" name="ipAddress"> <br/>主机名:<input type="text" name="hostName"> </form> </body> </html> <script language="javascript"> var sMacAddr=""; var sIPAddr=""; var sDNSName=""; var service = locator.ConnectServer(); service.Security_.ImpersonationLevel=3; service.InstancesOfAsync(foo, 'Win32_NetworkAdapterConfiguration'); </script> <script FOR="foo" EVENT="OnObjectReady(objObject,objAsyncContext)" LANGUAGE="JScript"> if(objObject.IPEnabled != null && objObject.IPEnabled != "undefined" && objObject.IPEnabled == true){ if(objObject.IPEnabled && objObject.IPAddress(0) !=null && objObject.IPAddress(0) != "undefined") sIPAddr = objObject.IPAddress(0); if(objObject.MACAddress != null &&objObject.MACAddress != "undefined") sMacAddr = objObject.MACAddress; if(objObject.DNSHostName != null &&objObject.DNSHostName != "undefined") sDNSName = objObject.DNSHostName; } </script> <script FOR="foo" EVENT="OnCompleted(hResult,pErrorObject, pAsyncContext)" LANGUAGE="JScript"> myForm.macAddress.value=sMacAddr; myForm.ipAddress.value=sIPAddr; myForm.hostName.value=sDNSName; </script>
4、如何在.net中获取电脑名称,IP地址,用户名,计算机所在域名(转载)
获取服务器电脑名: Page.Server.ManchineName获取用户信息: Page.User获取客户端电专脑名:Page.Request.UserHostName获取客户端电脑IP: Page.Request.UserHostAddress2. 在网络编程属中的通用方法:获取当前电脑名: static System.Net.Dns.GetHostName()根据电脑名取出全部IP地址: static System.Net.Dns.Resolve(电脑名).AddressList也可根据IP地址取出电脑名: static System.Net.Dns.Resolve(IP地址).HostName3. 系统环境类的通用属性:
5、asp.net 怎么得到url 主要地址 ?如图:
你的问题分两部分:抄
一、要获取当前域名:Request.Url.Host(不包括端口)
二、获取当前的应用程序名:Request.ApplicationPath
好了、该怎么拼接,你自己看着办啦!
★若无疑问请及时采纳,采纳就是对回答者的尊重,不要放着题目不处理,浪费百度资源,在我的回答下方【选为满意答案】按钮,点一下就行,谢谢★
6、ASP.NET如何获取网址中的ID
int a;
a=Request.QueryString["id"]==null?0:int.Pares(Request.QueryString["id"].ToString());
这样应该可以的,如果取不到ID,就赋0给i
但是如果穿过的值如果不能转换到int型,那还是会出错回
可以改答造成
int a = 0;
try{
a=Request.QueryString["id"]==null?0:int.Pares(Request.QueryString["id"].ToString());
}
catch{}
不过用try会降低效率
7、如何在.NET中获取电脑名,IP地址, 用户名, 计算机所在域名
获取服务器电脑名: Page.Server.ManchineName获取用户信息: Page.User获取客户端电脑专名:Page.Request.UserHostName获取客户端电脑IP: Page.Request.UserHostAddress2. 在网络编程中的属通用方法:获取当前电脑名: static System.Net.Dns.GetHostName()根据电脑名取出全部IP地址: static System.Net.Dns.Resolve(电脑名).AddressList也可根据IP地址取出电脑名: static System.Net.Dns.Resolve(IP地址).HostName3. 系统环境类的通用属性:
8、如何在不使用request的情况下获取网站的域名。(asp.net 2.0/c#语言)
应该没有这个函数。域名是在request中写的。
你可以把域名写在配置文件中。