经典ASP Server.MapPath无法正常工作

时间:2020-12-21 01:54:30

The site I'm working on is done in Classic ASP, and I'm trying to do it as best as possible. I've abstracted it out into a Rails-like directory structure:

我正在研究的网站是在经典ASP中完成的,我正尽力做到最好。我已将其抽象为类似Rails的目录结构:

app_name
 - app
   - includes
     - helpers
     - lib
     - partials
  - public
    - stylesheets
    - images
    - javascripts

I've created some Rails-like helpers, for example:

我创建了一些类似Rails的助手,例如:

Function ImageTag(ByVal imageFileName, ByVal altText)
  path = Server.MapPath(IMAGE_ROOT & imageFileName & ".jpg")
  ImageTag = "<img src=""" & path & """ title=""" & altText & """ alt=""" & altText & """ />"
End Function

Which is used thusly:

这样使用的是:

<%= ImageTag("my_pic") %>

With "IMAGE_ROOT" defined as "../public/images/" in a config file. I'm doing development on XP so the site is set as a virtual directory. However, the image won't load on the webpage at all. It's displaying the right path to it, because I can copy/paste it into my browser and view the image - it just won't display on the page for some reason. The same thing goes for my CSS stylesheet - the path is right but the page isn't rendering it at all.

在配置文件中将“IMAGE_ROOT”定义为“../public/images/”。我正在XP上进行开发,因此该站点被设置为虚拟目录。但是,图像根本不会加载到网页上。它正在显示正确的路径,因为我可以将其复制/粘贴到我的浏览器中并查看图像 - 由于某种原因它不会显示在页面上。我的CSS样式表也是如此 - 路径是正确的,但页面根本没有呈现它。

Any suggestions?

4 个解决方案

#1


-1  

An excellent tool to use when troubleshooting these types of issues is Fiddler. It will show you the calls and responses directly bewtween your web browser and the server. It works out of the box with IE and FireFox support is just a config setting away.

Fiddler是解决这些类型问题时使用的绝佳工具。它将直接显示您的Web浏览器和服务器之间的调用和响应。它开箱即用IE和FireFox支持只是一个配置设置。

I'ver personally used Fiddler to track down image load issues, CSS problems, caching issues, redirect errors, and even have used it to tamper with URL variables to try breaking/hacking my sites.

我个人使用Fiddler来跟踪图像加载问题,CSS问题,缓存问题,重定向错误,甚至用它来篡改URL变量来尝试破解/黑客攻击我的网站。

Fiddler Website

#2


3  

You're probably going to run into issues mixing server-side and web directories.

您可能会遇到混合服务器端和Web目录的问题。

Server.MapPath will give you C:\InetPub\...\public\images\my_pic.jpg when you probably want /public/images/my_pic.jpg. The browser has no way of grabbing the first from your server.

当你想要/public/images/my_pic.jpg时,Server.MapPath会给你C:\ InetPub \ ... \ public \ images \ my_pic.jpg。浏览器无法从服务器中获取第一个。

The image has to be available via your domain: localhost/public/images/my_pid.jpg.

图像必须通过您的域提供:localhost / public / images / my_pid.jpg。


I assume, since you can view the image, that you're developing on the same box that's hosting it? If that's the case, you can view the image cause it's just opened as a local file by the browser. Everyone else has to use HTTP-only.

我假设,既然您可以查看图像,那么您正在托管它的同一个盒子上进行开发?如果是这种情况,您可以查看图像,因为它刚刚被浏览器打开为本地文件。其他人都必须使用HTTP。

#3


0  

-Could it be an issue with the generated html?
-You might want to try making IMAGE_ROOT an absolute path like "/public/images" instead of the relative one (if possible).
-Also you could look at the IIS logs to see if you're getting 404 errors for the images and css files.

- 这是生成的HTML的问题吗? - 您可能想尝试将IMAGE_ROOT设为绝对路径,例如“/ public / images”而不是相对路径(如果可能)。 - 您还可以查看IIS日志,看看是否有图像和css文件的404错误。

#4


0  

If app_name/app is the root of your IIS-site then you must at app_name/app as a virtual directory in your IIS site. As it is only static content there you do not need to permissions to execute .asp scripts either.

如果app_name / app是IIS站点的根目录,则必须将app_name / app作为IIS站点中的虚拟目录。由于它只是静态内容,因此您无需执行.asp脚本的权限。

#1


-1  

An excellent tool to use when troubleshooting these types of issues is Fiddler. It will show you the calls and responses directly bewtween your web browser and the server. It works out of the box with IE and FireFox support is just a config setting away.

Fiddler是解决这些类型问题时使用的绝佳工具。它将直接显示您的Web浏览器和服务器之间的调用和响应。它开箱即用IE和FireFox支持只是一个配置设置。

I'ver personally used Fiddler to track down image load issues, CSS problems, caching issues, redirect errors, and even have used it to tamper with URL variables to try breaking/hacking my sites.

我个人使用Fiddler来跟踪图像加载问题,CSS问题,缓存问题,重定向错误,甚至用它来篡改URL变量来尝试破解/黑客攻击我的网站。

Fiddler Website

#2


3  

You're probably going to run into issues mixing server-side and web directories.

您可能会遇到混合服务器端和Web目录的问题。

Server.MapPath will give you C:\InetPub\...\public\images\my_pic.jpg when you probably want /public/images/my_pic.jpg. The browser has no way of grabbing the first from your server.

当你想要/public/images/my_pic.jpg时,Server.MapPath会给你C:\ InetPub \ ... \ public \ images \ my_pic.jpg。浏览器无法从服务器中获取第一个。

The image has to be available via your domain: localhost/public/images/my_pid.jpg.

图像必须通过您的域提供:localhost / public / images / my_pid.jpg。


I assume, since you can view the image, that you're developing on the same box that's hosting it? If that's the case, you can view the image cause it's just opened as a local file by the browser. Everyone else has to use HTTP-only.

我假设,既然您可以查看图像,那么您正在托管它的同一个盒子上进行开发?如果是这种情况,您可以查看图像,因为它刚刚被浏览器打开为本地文件。其他人都必须使用HTTP。

#3


0  

-Could it be an issue with the generated html?
-You might want to try making IMAGE_ROOT an absolute path like "/public/images" instead of the relative one (if possible).
-Also you could look at the IIS logs to see if you're getting 404 errors for the images and css files.

- 这是生成的HTML的问题吗? - 您可能想尝试将IMAGE_ROOT设为绝对路径,例如“/ public / images”而不是相对路径(如果可能)。 - 您还可以查看IIS日志,看看是否有图像和css文件的404错误。

#4


0  

If app_name/app is the root of your IIS-site then you must at app_name/app as a virtual directory in your IIS site. As it is only static content there you do not need to permissions to execute .asp scripts either.

如果app_name / app是IIS站点的根目录,则必须将app_name / app作为IIS站点中的虚拟目录。由于它只是静态内容,因此您无需执行.asp脚本的权限。