get current page from url

前端 未结 6 1687
无人及你
无人及你 2020-12-30 19:45

I want to write a c# method to retrieve the current page. eg Default6.aspx I know I can do the following:

string url = HttpContext.Current.Request.Url.Absolu         


        
相关标签:
6条回答
  • 2020-12-30 20:15

    The class you need is System.Uri

    Dim url As System.Uri = Request.UrlReferrer 
    Debug.WriteLine(url.AbsoluteUri)   ' => http://www.mysite.com/default.aspx
    Debug.WriteLine(url.AbsolutePath)  ' => /default.aspx
    Debug.WriteLine(url.Host)          ' => http:/www.mysite.com
    Debug.WriteLine(url.Port)          ' => 80
    Debug.WriteLine(url.IsLoopback)    ' => False
    

    http://www.devx.com/vb2themax/Tip/18709

    0 讨论(0)
  • 2020-12-30 20:15
    Request.Url.Segments.Last()
    

    Another option.

    0 讨论(0)
  • 2020-12-30 20:25

    A simple function like below will help :

    public string GetCurrentPageName() 
    { 
        string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
        System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath); 
        string sRet = oInfo.Name; 
        return sRet; 
    } 
    
    0 讨论(0)
  • 2020-12-30 20:26

    Try this:

    path.Substring(path.LastIndexOf("/");
    
    0 讨论(0)
  • 2020-12-30 20:26

    You could try this below.

    string url = "http://localhost:1302/TESTERS/Default6.aspx";
    
    string fileName = System.IO.Path.GetFileName(url);
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-30 20:27
    Path.GetFileName( Request.Url.AbsolutePath )
    
    0 讨论(0)
提交回复
热议问题