導航:首頁 > IDC知識 > aspnet獲取域名

aspnet獲取域名

發布時間:2021-02-06 00:39:57

1、c#的哪個方法可以獲得主機域名

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中寫的。
你可以把域名寫在配置文件中。

與aspnet獲取域名相關的知識