添加一个阿克尔到aspx页面,并获得域名
问题描述:
你好我想补充一点,在域名拉锚,然后我就可以有什么之后例如添加一个阿克尔到aspx页面,并获得域名
<a href="GET_THE_DOMAIN+/admin/pages/customers/add.aspx">ADD CUSTOMERS</a>
?我怎样才能没有,因为我们将使用同一网站硬编码,但与不同的内容不同域的域名,换句话说,唯一的变化是域
谢谢
答
你就不能使用绝对链接没有的域名?
<a href="/admin/pages/customers/add.aspx">ADD CUSTOMERS</a>
答
您可以创建一个基本页面,所有的ASPX页面,从在该基地页面添加的功能继承:
public string RootUrl(bool includeAppPath = false)
{
var context = HttpContext.Current;
var port = context.Request.ServerVariables["SERVER_PORT"];
if (port == null || port == "80" || port == "443")
{
port = "";
} else
{
port = ":" + port;
}
var protocol = context.Request.ServerVariables["SERVER_PORT_SECURE"];
if (protocol == null || protocol == "0")
{
protocol = "http://";
}else
{
protocol = "https://";
}
var appPath = "";
if (includeAppPath)
{
appPath = context.Request.ApplicationPath;
if (appPath == "/")
appPath = "";
}
var sOut = protocol + context.Request.ServerVariables["SERVER_NAME"] + port + appPath + "/";
return sOut;
}
然后在你的锚标签,你可以调用该函数如下:
<a href='<%= RootUrl() %>/admin/pages/customers/add.aspx'>ADD CUSTOMERS</a>
答
您可以使用以下方法:
<a href="<%=Request.Url.Host%>/admin/pages/customers/add.aspx">ADD CUSTOMERS</a>
话虽如此,为什么你不能只使用没有域的绝对URL?
你不是指相对的(不是绝对的) – gb2d 2012-02-07 16:08:23