How can I get the baseurl of site?

后端 未结 12 1635
借酒劲吻你
借酒劲吻你 2020-11-30 17:43

I want to write a little helper method which returns the base URL of the site. This is what I came up with:

public static string GetSiteUrl()
{
    string ur         


        
12条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 17:50

    you could possibly add in the port for non port 80/SSL?

    something like:

    if (HttpContext.Current.Request.ServerVariables["SERVER_PORT"] != null && HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString() != "80" && HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString() != "443")
                {
                    port = String.Concat(":", HttpContext.Current.Request.ServerVariables["SERVER_PORT"].ToString());
                }
    

    and use that in the final result?

提交回复
热议问题