Asp.Net Absolute Path of a URL

后端 未结 5 1075
天命终不由人
天命终不由人 2021-01-30 01:54

To make it simpler for a webapp to share files with another app on a different server, I\'m using a base href tag in my master page. As many people have discovered, this breaks

相关标签:
5条回答
  • 2021-01-30 02:19

    I have used following and it worked for me both client and the server.

    string surl = string.Format("{0}://{1}",
        HttpContext.Current.Request.Url.Scheme,
        HttpContext.Current.Request.Url.Authority);
    
    0 讨论(0)
  • 2021-01-30 02:19

    Code :

    string loginUrl = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/") + "Login/Login.aspx?UserName=" + LoggedinUser["UserName"] + "&Password=" + LoggedinUser["Password"];
    
    0 讨论(0)
  • 2021-01-30 02:20

    Old post but here is another slightly less verbose method

    var baseUri = new Uri(HttpContext.Current.Request.Url, "/");
    
    0 讨论(0)
  • 2021-01-30 02:20

    Using string interpolation:

    string redirectUri = $"{this.Request.Url.Scheme}://{this.Request.Url.Authority}{this.Request.ApplicationPath}account/signedout";
    

    Substitute 'this' for 'HttpContext' or 'HttpContext.Current' based on context.

    0 讨论(0)
  • 2021-01-30 02:25

    I have used this in the past:

    // Gets the base url in the following format: 
    // "http(s)://domain(:port)/AppPath"
    HttpContext.Current.Request.Url.Scheme 
        + "://"
        + HttpContext.Current.Request.Url.Authority 
        + HttpContext.Current.Request.ApplicationPath;
    
    0 讨论(0)
提交回复
热议问题