超级连接问题地址栏总缺少根目录
我在dw中用图片做了个超级连接,并且能够实现连接。把所有代码拷到.net环境下,运行不成功,总是缺少根目录。 dw中 <a href="../product/product.aspx"><img src="../images/index_10.gif" width="99" height="46" border="0"></a>
我的根目录是aa,aa下有product文件夹,images,indext.aspx,在.net下运行地址拦出现下边情况:
http://localhost/product/product.aspx 如果加上http://localhost/aa/product/product.aspx能够运行。请问这是什么原因啊?谢谢!!!
问题点数:20、回复次数:11Top
1 楼xiahouwen(武眉博<活靶子.NET>)回复于 2006-03-06 13:26:48 得分 0
<a href="/aa/product/product.aspx">Top
2 楼coldpanth(^War3^)回复于 2006-03-06 13:28:26 得分 0
问题说的有点不太明白,我大概的理解是,如下目录结构
aa目录下有子目录
--product
product为虚拟目录
现在访问http://localhost/product/xxxxx.aspx,../找不到aa
如果这样的话,是因为../以经超出product虚拟目录的范围(product是最上层了),为product虚拟目录新增虚拟目录,也就是将aa做为product的虚拟目录试试.Top
3 楼hanchi8008(寒池)回复于 2006-03-06 13:46:19 得分 0
再说清楚点:.net下,我做了用户控件,用来实现首页的顶部。其中“产品”是图片超连接。文件夹如下:
aa
--images
--product
--product.aspx
--indext.aspx
--userctol
--head.ascx
head.ascx下的代码
<a href="../product/product.aspx"><img src="../images/index_10.gif" width="99" height="46" border="0"></a>
运行首页 点击 产品 地址栏是:http://localhost/product/product.aspx
按说上边代码是对的呀?为什么一运行就不对。 谢谢各位1
Top
4 楼zwkandy(已经愤怒)回复于 2006-03-06 13:47:32 得分 0
“我的根目录是aa,aa下有product文件夹”
我想应该是“把所有代码拷到.net环境下”后,没有在这台机子建一个虚拟目录aa指向程序所在文件夹。Top
5 楼zwkandy(已经愤怒)回复于 2006-03-06 13:53:13 得分 2
“如果加上http://localhost/aa/product/product.aspx能够运行”
把现在的iis里面的指向(如:C:\Inetpub\wwwroot\aa)改成指向(C:\Inetpub\wwwroot)试试看啊Top
6 楼turenjie(拉倒)回复于 2006-03-06 13:59:28 得分 3
hanchi8008 (寒池) 朋友,你这个问题我碰到过!
你可以在web.config里加个变量的值为LocalString = “http://localhost”;
然后你可以把LocalString 写入该接连中!
即可
Top
7 楼xiahouwen(武眉博<活靶子.NET>)回复于 2006-03-06 14:03:51 得分 5
/// <summary>
/// 网站原始地址 like:http://www.aspxboy.com
/// </summary>
public static string BaseUrl
{
get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority); }
}
/// <summary>
/// 网站原始地址 like:http://www.aspxboy.com:8080
/// </summary>
/// <returns></returns>
public static string GetHostUrl()
{
string securePort = HttpContext.Current.Request.ServerVariables["SERVER_PORT_SECURE"];
string protocol = securePort == null || securePort == "0" ? "http" : "https";
string serverPort = HttpContext.Current.Request.ServerVariables["SERVER_PORT"];
string port = serverPort == "80" ? string.Empty : ":" + serverPort;
string serverName = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
return string.Format("{0}://{1}{2}" , protocol, serverName, port );
}
/// <summary>
/// 应用程序虚拟路径 like: http://www.aspxboy.com/dir
/// </summary>
public static string SiteUrl
{
get
{
return Globals.BaseUrl + Globals.AppPath;
}
}
/// <summary>
/// 应用程序路径
/// </summary>
public static string AppPath
{
get
{
string applicationPath = "/";
if(HttpContext.Current != null)
{
applicationPath = HttpContext.Current.Request.ApplicationPath;
}
if (applicationPath == "/")
{
return string.Empty;
}
else
{
if (applicationPath.EndsWith("/"))
{
return applicationPath;
}
else
{
return applicationPath + "/";
}
}
}
}
public static string ResolveUrl(string relativeUrl)
{
if (relativeUrl.StartsWith("~"))
return Globals.SiteUrl + relativeUrl.Substring(1);
else if (relativeUrl.StartsWith("http://") || relativeUrl.StartsWith("https://"))
return relativeUrl;
else
throw new ArgumentException("URLs passed to Helpers.ResolveUrl() must begin with ~, http://, or https://");
}
该ResolveUrl方法和webcontrol的ResolveUrl方法功能相同
放到basepage内 每个页面都可以用
Top
8 楼flyinging(一路走来)回复于 2006-03-06 14:29:35 得分 0
从aa开始写,根目录是指iis的根目录,不是指你的虚似目录Top
9 楼GSXiaoXiao(牧羊人)回复于 2006-03-06 14:59:16 得分 10
<a href="../product/product.aspx"><img src="../images/index_10.gif" width="99" height="46" border="0"></a>
改为:
<a href="<%=Request.ApplicationPath%>/product/product.aspx"><img src="../images/index_10.gif" width="99" height="46" border="0"></a>Top
10 楼hanchi8008(寒池)回复于 2006-03-06 16:14:04 得分 0
谢谢大家了。但我分不多,下次补上吧!Top
11 楼turenjie(拉倒)回复于 2006-03-13 11:59:22 得分 0
收藏了!哈哈Top




