Asp.net le uğraşıpta URl parçalarıyla ve yollarla uğraşmayan yoktur heralde.
Gördüğüm kadarıyla bir çok kişi Request.ServerVariables ile bu işlerini hallediyor ,
ancak bu yöntemle HTTP_REFERER vb gibi isimleri ezberlemeniz gerekir yada index numarasını.
Bunlarla uğraşmak yerine Request objesinin altında hazır tanımlı değerler mevcut , bunları kullanarak zaman harcamamış olursunuz.
işte örnekler;
adres: http://localhost:96/mkocer/Temp/Test.aspx?query=arg#fragment
| Request.ApplicationPath: |
/mkocer |
| Request.CurrentExecutionFilePath: |
/mkocer/Temp/Test.aspx |
| Request.FilePath: |
/mkocer/Temp/Test.aspx |
| Request.Path: |
/mkocer/Temp/Test.aspx |
| Request.PathInfo: |
|
| Request.PhysicalApplicationPath: |
D:\Inetpub\wwwroot\mkocer\ |
| Request.QueryString: |
/mkocer/Temp/Test.aspx?query=arg |
| Request.Url.AbsolutePath: |
/mkocer/Temp/Test.aspx |
| Request.Url.AbsoluteUri: |
http://localhost:96/mkocer/Temp/Test.aspx?query=arg |
| Request.Url.Fragment: |
|
| Request.Url.Host: |
localhost |
| Request.Url.Authority: |
localhost:96 |
| Request.Url.LocalPath: |
/mkocer/Temp/Test.aspx |
| Request.Url.PathAndQuery: |
/mkocer/Temp/Test.aspx?query=arg |
| Request.Url.Port: |
96 |
| Request.Url.Query: |
?query=arg |
| Request.Url.Scheme: |
http |
| Request.Url.Segments: |
/
mkocer/
Temp/
Test.aspx
|
Dikkat etmeniz gereken nokta ; .net public static fonksiyon yada metodlarda request objesine direk erişim imkanı vermez.
Bunu aşmak için System.Web.HttpContext.Current.Request şeklinde kullanmanız gerekir
Mustafa KOÇER
mkocer@dotnetkosesi.com
Bu yazıyı ilk değerlendiren siz olun
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5