Request对象的使用

本文介绍了如何使用ASP.NET获取客户端的各种信息,包括操作系统、浏览器类型及版本等,并展示了应用程序路径、URL地址以及物理文件路径等多种实用代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

出自:http://www.51fy.cn/web/ASPNET/200705/33085.html

Response.Write("客户端的操作系统:" + Request.Browser.Platform + "<br>"); // WinNT

Response.Write("客户端用的浏览器:" + Request.Browser.Browser + "<br>"); // IE

Response.Write("客户端浏览器的版本:" + Request.Browser.Version + "<br>"); // 6.0

Response.Write("客户端FrameWork的版本:" + Request.Browser.ClrVersion.ToString()+"<br>"); // 2.0.50727

Response.Write("客户端浏览器是否有后退按钮:" + Request.Browser.HasBackButton.ToString()+"<br>"); // True

Response.Write("判断客户端浏览器类型:" + Request.Browser.IsBrowser("IE").ToString () + "<br>"); // True (大小写没差别)

Response.Write("判断客户端是几位机:" + ((Request.Browser.Win16==true)? "16位机":"32位机") + "<br>"); // 32位机

//Response.Write(""+Request.ContentEncoding.EncodingName+"<br>");

Response.Write("ApplicationPath应用程序根路径: " + Request.ApplicationPath + "<br>"); // /study1

Response.Write("AppRelativeCurrentExecutionFilePath应用程序根虚拟路径: " + Request.AppRelativeCurrentExecutionFilePath + "<br>"); // ~/Default.aspx

Response.Write("CurrentExecutionFilePath当前请求的虚拟路径: " + Request.CurrentExecutionFilePath + "<br>"); // /study1/textPath/path.aspx

Response.Write("AppDomain.CurrentDomain.BaseDirectory 获取基目录: " + AppDomain.CurrentDomain.BaseDirectory + "<br>"); // C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005

Response.Write("原始URL地址(包括URL的参数)Request.RawUrl" + Request.RawUrl+"<br>"); // /study1/Default3.aspx?type=dddd

Response.Write("物理文件路径PhysicalPath:" + Request.PhysicalPath + "<br>"); // C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesstudy1Default3.aspx

Response.Write("应用程序根目录物理文件路径PhysicalApplicationPath:" + Request.PhysicalApplicationPath + "<br>"); // C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesstudy1

Response.Write("程序集路径:AppDomain.CurrentDomain.RelativeSearchPath" + AppDomain.CurrentDomain.RelativeSearchPath + "<br>"); // C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesstudy1in

Response.Write("虚拟路径对应的物理路径Server.MapPath " + Server.MapPath("Default3.aspx") + "<br>"); //C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005WebSitesstudy1Default3.aspx

Response.Write("获取绝对的URI:Request.Url.AbsoluteUri" + Request.Url.AbsoluteUri.ToString()+"<br>"); // http://localhost:1035/study1/Default3.aspx?type=dddd

Response.Write("获取主机名:端口号" + Request.Url.Authority + "<br>"); // localhost:1035

Request.SaveAs(Request.PhysicalApplicationPath + "abc.xml", true);//保存

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值