从应用程序在IIS中选择文件正确的路径 [英] Select correct path for files from App Under IIS

查看:160
本文介绍了从应用程序在IIS中选择文件正确的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继承在IIS托管的.net应用程序。 previously它会一直在IIS中它自己的网站。现在在我的开发环境,我要下的默认网站运行(在生产它仍然会按照自己的站点。

I have inherited an .NET app that is hosted on IIS. Previously it would have been its own site within IIS. Now in my Dev environment I have to run it under Default WebSite (in Production it will still run as its own site.

因此​​,在开发我有加载脚本和CSS文件的问题 - 所以我右键单击默认Web站点的开发和添加应用程序 - 调用新的应用程序 - MyApp的并指向磁盘上的物理位置。

So in Dev I was having problems loading scripts and css files - so I right click Default Web Site in Dev and Add Application - call the new App - MyApp and point to the physical location on disk.

所以previously样式表会被加载:

So previously style sheets would have been loaded:

href="/css/folder/mystylesheet.css"

和js文件:

src="/jslib/jquery-1.9.1.js"

这工作得很好,当应用程序托管作为IIS在其自己的网站,这还需要在生产中发生(只是没有在我的dev)所以在开发中,我需要改变,因为下面的CSS和JS:

which worked fine when the application is hosted as its own site within IIS and which still needs to happen in Production (just not in my dev) So in dev I need to change the css and js as below:

href="~/css/folder/mystylesheet.css" (note ~ added)

src="./jslib/jquery-1.9.1.js" (note . added)

和现在在默认网站上的JS和CSS文件MyApp的加载。但是有一些简单的,我可以在IIS或webconfig做开/关很容易地在开发/生产这个行为,而不是编辑在这里的脚本和CSS文件加载的所有的地方 - 因为我知道在某个时刻的文件,将得到遏制成生产与该路径不正确

and now the js and css files for MyApp under Default website are loaded. However is there something simple I can do in IIS or webconfig to switch this behaviour on/off easily in Dev/Production rather than editing all the places where scripts and css files are loaded - as I know at some point a file will get checked into Production with the path incorrect

另一个问题是有很多环节是整个都是相对的网站,以便为/Link/Page.aspx现在在MyApp的突破下默认网站托管

The other problem is there is numerous links throughout the site that are all relative so were /Link/Page.aspx which now break in MyApp hosted under Default Website

修改

看着从这个下面的答案<一个href=\"http://stackoverflow.com/questions/2411151/relative-path-not-working-when-website-is-deployed\">question

Looking at the answer below from this question

在ASP.NET中,很多时候你需要使用波浪号(〜)来获取应用程序的根目录,所以你的路径看起来像〜/样式表/的main.css
当指定用/你表明服务器的根,所以如果你有你在一个虚拟目录网站,它不会被考虑,但如果该网站托管为默认站点,路径将有资格开始的路径:
例如:一个名为foo.net在名为应用程序/样式的虚拟目录托管站点服务器将转化为foo.net/stylesheet~~V不foo.net/app/stylesheet

我的所有路径开始/(也就是将服务器的根目录) - 什么,我需要弄清楚是有什么我可以添加到Web.config中,对于开发将让我指定的虚拟应用程序MyApp的需要加以考虑(只是为了开发 - 这可能那么网页被删除变换的生产web.config文件

All my paths start with / (i.e going to server root) - what I need to figure out is there something I could add to web.config that for Dev would let me specify The Virtual Application MyApp needs to be taken into account (just for Dev - this could then be removed in Web Transform for Production web.config file

推荐答案

简短的回答是否定的,有没有一个地方,你可以处理网站的位置。这是因为有可能要多种可能的结果,其中包括:

The short answer is no, there is not one single place where you can deal with the site's location. That's because there are many possible outcomes that you might want, including:


  • 的网站从IIS根目录服务和域名根访问(或没有)

  • 网站从IIS中的子文件夹和服务在访问相同的路径(或没有)

  • IIS重写规则(入站和出站),增加了公共和私人路径之间的映射层

  • 网站映射子域,DNS通配符映射(其中请求由主机区别)等

  • 网站映射到子应用程序,继承或不继承重写规则(和其他配置)

  • 所有上述

与此同时,在有些情况下,你与路径接口中的很多地方:

At the same time, there are many places where you interface with paths:


  • 内部的物理路径,通常是磁盘访问和虚拟路径通常需要映射

  • 内部虚拟路径

  • 内部ASP.NET路径,如虚拟但他们可以应用相对路径(使用),这IIS并不总是识别

  • 面向公众的路径

  • 以上所有可以是相对或绝对

  • internal physical paths, usually for disk access, and usually requiring mapping of virtual path
  • internal virtual paths
  • internal ASP.NET paths, like virtual paths except that they can be app-relative (using ~), which IIS doesn't always recognize
  • public-facing paths
  • all of the above can be relative or absolute

所以,是的,这是一个烂摊子。

So yeah, it's a mess.

有关你的情况,最简单的事情可能是使开发环境与生产环境相似。除非你的移动网站的直播,所有委托的路径引用到配置感知功能可能是更多的麻烦比它的价值。

For your case, the simplest thing is probably to make the development environment mirror the production environment. Unless you're moving the live site, delegating all the path references to a configuration-aware function is probably more trouble than it's worth.

这篇关于从应用程序在IIS中选择文件正确的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆