开发者

get application url from current request

开发者 https://www.devze.com 2023-03-14 07:26 出处:网络
I am writing a c# application. I am accessing a page eg http://dev.mysite.com/page.a开发者_StackOverflowspx

I am writing a c# application.

I am accessing a page eg http://dev.mysite.com/page.a开发者_StackOverflowspx

How can I retrieve from the current context this http://dev.mysite.com/

I want to use this when creating url's in different environments so need to read it from the current request context.


Uri uri = new Uri("http://dev.mysite.com/page.aspx");
string authority = uri.GetLeftPart(UriPartial.Authority);
// authority will equal to http://dev.mysite.com

or if you are inside this page.aspx you could directly use the Request.Url property:

string authority = Request.Url.GetLeftPart(UriPartial.Authority);


string baseUrl = Request.Url.GetLeftPart(UriPartial.Authority);
0

精彩评论

暂无评论...
验证码 换一张
取 消