Cấp bậc tác giả:

DOTNET

Cách để lấy địa chỉ hiện tại trên thanh URL trong ASP.NET

Được viết bởi webmaster ngày 03/02/2017 lúc 04:43 PM
HttpContext gói gọn tất cả các thông tin HTTP.
  • 0
  • 9386

Cách để lấy địa chỉ hiện tại trên thanh URL trong ASP.NET

HttpContext gói gọn tất cả các thông tin HTTP.
Giả sử bạn có trang như sau:
http://localhost:57864/TinTuc/Chi-Tiet-Tin-Tuc.aspx?TieuDe=So-sanh-MacBook-Air-va-Pro-Nen-mua-MacBook-dong-nao-tot-nhat

Bây giờ chúng ta sẽ lấy thông tin từ HttpContext:

HttpContext.Current.Request.Url.AbsolutePath = "/TinTuc/Chi-Tiet-Tin-Tuc.aspx"
HttpContext.Current.Request.Url.AbsoluteUri = "http://localhost:57864/TinTuc/Chi-Tiet-Tin-Tuc.aspx?TieuDe=So-sanh-MacBook-Air-va-Pro-Nen-mua-MacBook-dong-nao-tot-nhat"
HttpContext.Current.Request.Url.Authority = "localhost:57864"
HttpContext.Current.Request.Url.DnsSafeHost = "localhost"
HttpContext.Current.Request.Url.Host = "localhost"
HttpContext.Current.Request.Url.LocalPath = "/TinTuc/Chi-Tiet-Tin-Tuc.aspx"
HttpContext.Current.Request.Url.OriginalString = "http://localhost:57864/TinTuc/Chi-Tiet-Tin-Tuc.aspx?TieuDe=So-sanh-MacBook-Air-va-Pro-Nen-mua-MacBook-dong-nao-tot-nhat"
HttpContext.Current.Request.Url.PathAndQuery = "/Chi-Tiet-Tin-Tuc.aspx?TieuDe=So-sanh-MacBook-Air-va-Pro-Nen-mua-MacBook-dong-nao-tot-nhat"
HttpContext.Current.Request.Url.Port = 57864
HttpContext.Current.Request.Url.Query = "?TieuDe=So-sanh-MacBook-Air-va-Pro-Nen-mua-MacBook-dong-nao-tot-nhat"
HttpContext.Current.Request.Url.Segments[0] = "/"
HttpContext.Current.Request.Url.Segments[1] = "TinTuc/"
HttpContext.Current.Request.Url.Segments[2] = "Chi-Tiet-Tin-Tuc.aspx"

Nguồn bài viết: DOTNET.VN

BÌNH LUẬN BÀI VIẾT

Bài viết mới nhất

LIKE BOX

Bài viết được xem nhiều nhất

HỌC HTML