【问题标题】:Why the links are not working when moving a page outside the root directory?为什么将页面移到根目录之外时链接不起作用?
【发布时间】:2010-09-05 21:26:58
【问题描述】:

我的网站在根目录下,即/www.lebmotor.com/web/content/。

我正在使用这个:

Dim appPath As String = HttpContext.Current.Request.ApplicationPath  
Dim directory As String = appPath & "/upload/" & Left(TableName, 2) & "/"  

获取路径并且它工作得很好。

但是当我创建一个新的子文件夹并将一些页面从根目录复制到子文件夹时,由于路径已更改,我的图像不显示。

这是来自根目录页面的链接:

http://www.lebmotor.com/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM

这是子文件夹中页面的链接:

http://www.lebmotor.com/ar/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM

那么我怎样才能像这样在子文件夹中创建链接:

http://www.lebmotor.com/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM


让我详细解释一下。首先,我有两个目录,它们都被设置为应用程序目录,如图所示:

/ar 子文件夹是一个应用程序,它是 Content 目录中原始应用程序的副本。

在ar/App_code 中有一个名为MGImages.vp 的类,当然它是Content/App_code 中原始类的副本。这个类的工作是显示来自Upload 子文件夹的照片。

这是保存照片路径的代码:

Dim appPath As String = HttpContext.Current.Request.ApplicationPath  
Dim directory As String = appPath & "/upload/" & Left(TableName, 2) & "/"  
If ImageType.ToUpper = "TN" Then  
    directory += "TN/"  
ElseIf ImageType.ToUpper = "LG" Then  
    directory += "LG/"  
Else  
    directory += "OT/"  
End If  

此类在Content 目录中运行良好,因为这将为我提供正确的路径:

http://www.lebmotor.com/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM

所有照片都应保存在两个目录的Content/arContent/Upload 文件夹中

但是在ar 目录中它会给我错误的路径:

http://www.lebmotor.com/ar/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM

目标是使路径像这样:

http://www.lebmotor.com/upload/VE/TN/6/VEListing-66-Photo1.jpg?ts=9/4/2010%201:45:17%20AM

我希望它显示来自Content/upload 的照片,而不是来自content/ar/upload 的照片。

【问题讨论】:

    标签: asp.net vb.net path root


    【解决方案1】:

    第一次构造图片路径时,可以去掉ar路径:

    Dim directory As String = appPath & "/upload/" & Left(TableName, 2) & "/" 
    directory = directory.Replace("/ar/", "")
    

    【讨论】:

    • 天啊!!!为什么我没有想到这么简单的事情??????这个答案让全世界最大的傻瓜!!! Mr.Oded 非常感谢您,非常感谢您,您是最棒的。有的人思考困难,而聪明的人则选择最简单、最有效的方法。再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2015-02-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多