In ASP.NET, what is the quickest way to get the base URl for a request?

后端 未结 1 1579
攒了一身酷
攒了一身酷 2021-01-11 21:57

Is there a fast way to get the scheme, host, port (only if not 80) and application path in ASP.NET?

As far as I know, I need to assemble the following pieces:

<
相关标签:
1条回答
  • 2021-01-11 22:23

    This should work:

    Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath
    

    Note that this may or may not end with a trailing "/" depending on if your app is hosted in the root of the site or in a sub directory.

    0 讨论(0)
提交回复
热议问题