Hi,
Use follwing method:
GetURL();
For example in MVC:
<link href="<%=GetURL()+""+Url.Content("~/Styles/Sitecss.css") %>" rel="stylesheet" type="text/css" />
<a href="<%=GetURL()+""+Url.Action("actionname","controllername")%>">Click here</a>
Method GetURL() :
public static string GetURL()
{
string URL = "";
try
{
string Port = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
if ((Port == null) | Port == "80" | Port == "443")
{
Port ="";
}
else
{
Port =":" + Port;
}
string Protocol = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
if ((Protocol == null) | Protocol == "0")
{
Protocol ="https://";
}
else
{
Protocol ="https://";
}
URL = Protocol +HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + Port + "";
}
catch (Exception ex)
{
}
return URL;
}
Posted On:
26-Apr-2015 02:57