asp.net獲取客戶端請求頁面信息

asp.net獲取客戶端上次請求的URL信息

UrlReferrer:是一個Uri對象

default1.aspx中的按鈕事件:

Response.Redirect("default2.aspx", false);

在default2.aspx頁面的page_load事件中:

string str = Request.UrlReferrer.AbsolutePath;  //獲取Uri的絕對路徑
string str1 = Request.UrlReferrer.Authority;   //獲取IP地址
string str2 = Request.UrlReferrer.AbsoluteUri;  //獲取絕對的Uri

Uri MyUrl = Request.UrlReferrer;
Response.Write("Referrer URL Port: " + Server.HtmlEncode(MyUrl.Port.ToString()) + "<br>");  //端口
Response.Write("Referrer URL Protocol: " + Server.HtmlEncode(MyUrl.Scheme) + "<br>");     //協議

Response.Write(str+"-"+str1+"-"+str2);

 用ASP.Net獲取客戶端網卡的MAC

using System.Text.RegularExpressions;
using System.Diagnostics;
public class test
{
        public test
        {}
        public static string GetCustomerMac(string IP) //para IP is the client's IP 
        { 
               string dirResults=""; 
               ProcessStartInfo psi  = new ProcessStartInfo(); 
               Process proc = new Process(); 
               psi.FileName = "nbtstat"; 
               psi.RedirectStandardInput = false; 
               psi.RedirectStandardOutput = true; 
               psi.Arguments = "-A " + IP; 
               psi.UseShellExecute = false; 
               proc = Process.Start(psi); 
               dirResults = proc.StandardOutput.ReadToEnd(); 
               proc.WaitForExit(); 
               dirResults=dirResults.Replace("\r","").Replace("\n","").Replace("\t","");

              Regex reg=new Regex("Mac[ ]{0,}Address[ ]{0,}=[ ]{0,}(?<key>((.)*?)) __MAC",RegexOptions.IgnoreCase|RegexOptions.Compiled); 
               Match mc=reg.Match(dirResults+"__MAC");

           if(mc.Success) 
            { 
                return mc.Groups["key"].Value; 
           } 
            else 
           { 
                reg=new Regex("Host not found",RegexOptions.IgnoreCase|RegexOptions.Compiled); 
                mc=reg.Match(dirResults); 
            if(mc.Success) 
            { 
                 return "Host not found!"; 
            } 
            else 
            { 
                 return ""; 
            } 
       }
  }
}

 

1. 在ASP.NET中專用屬性:
獲取服務器電腦名:Page.Server.ManchineName
獲取用戶信息:Page.User
獲取客戶端電腦名:Page.Request.UserHostName
獲取客戶端電腦IP:Page.Request.UserHostAddress

2. 在網絡編程中的通用方法:
獲取當前電腦名:static System.Net.Dns.GetHostName()
根據電腦名取出全部IP地址:static System.Net.Dns.Resolve(電腦名).AddressList
也可根據IP地址取出電腦名:static System.Net.Dns.Resolve(IP地址).HostName

3. 系統環境類的通用屬性:
當前電腦名:static System.Environment.MachineName
當前電腦所屬網域:static System.Environment.UserDomainName
當前電腦用戶:static System.Environment.UserName

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章