CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

超级连接问题地址栏总缺少根目录

楼主hanchi8008(寒池)2006-03-06 13:17:23 在 .NET技术 / ASP.NET 提问

我在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

相关问题

  • 我用asp操作excel成功,但为什么会在服务器端根目录生成很多连接文件?谁知道?
  • 我用vbscript操作excel成功,但为什么会在服务器端根目录生成很多连接文件?谁知道?
  • 使用idftp已经连接到服务器,怎么得到服务器根目录下的所有文件(文件及文件夹).......
  • 如何判断根目录?
  • 网站根目录问题
  • 文档根目录(一定给分)
  • 如何include根目录的文件
  • 硬盘的FAT表和根目录
  • 用root在根目录下 rm -rf * ......................................
  • tomcat 根目录泻露如何防止?

关键词

  • .net
  • 连接
  • 文件夹
  • 代码
  • 虚拟
  • 根目录
  • applicationpath
  • relativeurl
  • secureport
  • resolveurl

得分解答快速导航

  • 帖主:hanchi8008
  • zwkandy
  • turenjie
  • xiahouwen
  • GSXiaoXiao

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo