10

この質問をするのは私が最初ではないかもしれませんが、周りを見回しても探していたものが見つかりません。URLからベースURLを取得したい。私が試してみました

    HttpContext.Current.Request.Url.AbsoluteUri

それは私に完全なURLを返します

    http://localhost:59112/Resources/VideoPlayer.aspx?ID=resources1.mp4

ここまで必要です(例)

    http://localhost:59112/

ご協力いただきありがとうございます。

4

5 に答える 5

16

もう少し研究して..私はフォーラムから欲しいものを手に入れました..これは素晴らしい解決策です..

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

ありがとう

于 2012-09-24T16:01:28.500 に答える
5

URL例:http:// localhost:59112 / Resources / VideoPlayer.aspx?ID = resources1.mp4

HttpContext.Current.Request.Url.Authority

戻り値: "localhost:59112"

HttpContext.Current.Request.Url.Scheme & "://" & HttpContext.Current.Request.Url.Authority

戻り値: " http:// localhost:59112 "

于 2017-03-14T12:00:40.153 に答える
2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim address As Uri = New Uri("http://stackoverflow.com/questions/12568530/how-to-get-the-base-url-of-the-website-vb-net")
    MsgBox("http://" & address.Host)
End Sub
于 2016-09-22T02:29:21.183 に答える
0

.Net 4以降では、次を使用できます-

Dim Url as String = Request.Url.OriginalString
Dim Domain as String = Url.Replace(Request.PathAndQuery, "")

Output -
Url = "http://localhost:9898/content/page.aspx
Domain = "http://localhost:9898"
于 2018-04-04T19:16:41.190 に答える
-1

HttpContext.Current.Request.Url.Host

于 2014-10-07T03:00:08.427 に答える