在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
一 ASP.NET常用路径(path)获取方法与格式对照表 假设我们的网址为http://localhost:1897/ News/Press/Content.aspx?id=1019
(接上面*) Request.FilePath, Request.PathInfo, Request.Path, RequestRawUrl
如果请求的地址为http://www.cnblogs.com/default.aspx/books则 Request.FilePath值为http://www.cnblogs.com/default.aspx Request.PathInfo 值为 /books Request.Path 值为 http://www.cnblogs.com/default.aspx/books Request.RawUrl 值为 http://www.cnblogs.com/default.aspx/books 如果请求地址为http://www.cnblogs.com/defaut.aspx?id=1&name=kk则 Request.FilePath值为http://www.cnblogs.com/default.aspx Request.PathInfo 值为 ""(空字符串) Request.Path 值为 http://www.cnblogs.com/default.aspx Request.RawUrl 值为 http://www.cnblogs.com/default.aspx?id=1&name=kk
二 Request.ServerVariables集合中获取到的相关信息: foreach (string s in Request.ServerVariables)
另外,我们使用upload控件上传文件时,用HttpPostedFile 。例如: HttpPostedFile file = context.Request.Files[i];//这里的context.Request.Files就是上传的文件集合. PS:此处乃是利用HttpHandler..在Page页面中可以自己用其它办法多文件上传. 接着如何保存文件呢? 利用HttpPostedFile的SaveAs方法即可,如: file.SaveAs(SpecifiedPath); 此处的SpecifiedPath是上传文件的绝对路径. 至于如何获取上传文件的路径.我们可以利用Path类.来操作File.HttpPostedFile类中也包含了文件的基本信息.如文件名,大小,路径等等.Path类操作更齐全而已.接着就可以利用Server.MapPath()方法来进行转换.
为检验上面的理论,你可以编写一段code跑下就一清二楚啦。例: StringBuilder req = new StringBuilder(); req.Append("<table cellpadding=3 cellspacing=0 border=1>");
// Request.ApplicationPath req.Append("<tr><td>"); req.Append("Request.ApplicationPath"); req.Append("</td><td>"); req.Append("<b>" + Request.ApplicationPath + "</b>"); req.Append("</td></tr>");
// Request.PhysicalPath req.Append("<tr><td>"); req.Append("Request.PhysicalPath"); req.Append("</td><td>"); req.Append("<b>" + Request.PhysicalPath + "</b>"); req.Append("</td></tr>");
// System.IO.Path.GetDirectoryName(Request.PhysicalPath) req.Append("<tr><td>"); req.Append("System.IO.Path.GetDirectoryName(Request.PhysicalPath)"); req.Append("</td><td>"); req.Append("<b>" + System.IO.Path.GetDirectoryName(Request.PhysicalPath) + "</b>"); req.Append("</td></tr>");
// Request.PhysicalApplicationPath req.Append("<tr><td>"); req.Append("Request.PhysicalApplicationPath"); req.Append("</td><td>"); req.Append("<b>" + Request.PhysicalApplicationPath + "</b>"); req.Append("</td></tr>");
// System.IO.Path.GetFileName(Request.PhysicalPath) req.Append("<tr><td>"); req.Append("System.IO.Path.GetFileName(Request.PhysicalPath)"); req.Append("</td><td>"); req.Append("<b>" + System.IO.Path.GetFileName(Request.PhysicalPath) + "</b>"); req.Append("</td></tr>");
// Request.CurrentExecutionFilePath req.Append("<tr><td>"); req.Append("Request.CurrentExecutionFilePath"); req.Append("</td><td>"); req.Append("<b>" + Request.CurrentExecutionFilePath + "</b>"); req.Append("</td></tr>");
// Request.FilePath req.Append("<tr><td>"); req.Append("Request.FilePath"); req.Append("</td><td>"); req.Append("<b>" + Request.FilePath + "</b>"); req.Append("</td></tr>");
// Request.Path req.Append("<tr><td>"); req.Append("Request.Path"); req.Append("</td><td>"); req.Append("<b>" + Request.Path + "</b>"); req.Append("</td></tr>");
// Request.RawUrl req.Append("<tr><td>"); req.Append("Request.RawUrl"); req.Append("</td><td>"); req.Append("<b>" + Request.RawUrl + "</b>"); req.Append("</td></tr>");
// Request.Url.AbsolutePath req.Append("<tr><td>"); req.Append("Request.Url.AbsolutePath"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.AbsolutePath + "</b>"); req.Append("</td></tr>");
// Request.Url.AbsoluteUri req.Append("<tr><td>"); req.Append("Request.Url.AbsoluteUri"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.AbsoluteUri + "</b>"); req.Append("</td></tr>");
// Request.Url.Scheme req.Append("<tr><td>"); req.Append("Request.Url.Scheme"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Scheme + "</b>"); req.Append("</td></tr>");
// Request.Url.Host req.Append("<tr><td>"); req.Append("Request.Url.Host"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Host + "</b>"); req.Append("</td></tr>");
// Request.Url.Port req.Append("<tr><td>"); req.Append("Request.Url.Port"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Port + "</b>"); req.Append("</td></tr>");
// Request.Url.Authority req.Append("<tr><td>"); req.Append("Request.Url.Authority"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Authority + "</b>"); req.Append("</td></tr>");
// local Request.Url.LocalPath req.Append("<tr><td>"); req.Append("Request.Url.LocalPath"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.LocalPath + "</b>"); req.Append("</td></tr>");
// Request.PathInfo req.Append("<tr><td>"); req.Append("Request.PathInfo"); req.Append("</td><td>"); req.Append("<b>" + Request.PathInfo + "</b>"); req.Append("</td></tr>");
// Request.Url.PathAndQuery req.Append("<tr><td>"); req.Append("Request.Url.PathAndQuery"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.PathAndQuery + "</b>"); req.Append("</td></tr>");
// Request.Url.Query req.Append("<tr><td>"); req.Append("Request.Url.Query"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Query + "</b>"); req.Append("</td></tr>");
// Request.Url.Fragment // 原则上你应该无法从 Request.Url.Fragment 取得任何数据,因为通常 Browser 不会送出 #toc 这个部分 req.Append("<tr><td>"); req.Append("Request.Url.Fragment"); req.Append("</td><td>"); req.Append("<b>" + Request.Url.Fragment + "</b>"); req.Append("</td></tr>");
// Request.Url.Segments req.Append("<tr>"); req.Append("<td>"); req.Append("Request.Url.Segments"); req.Append("</td>"); req.Append("<td>"); string[] segments = Request.Url.Segments; foreach (string s in segments) { req.Append("<b>" + s + "</b>"); req.Append("<p>"); } req.Append("</td>"); req.Append("</tr>"); req.Append("</table>"); Response.Write(req.ToString()); 参考的文章: http://www.cnblogs.com/zyip/archive/2009/08/13/1544968.html 如有错误,请不吝指出。
另加上一个实例: // Builds an absolute URL |
请发表评论