将 ASP.NET MVC 应用程序部署到多个虚拟目录(URL 引用和 JS 文件问题)
我不确定我的问题是否命名正确,但问题是:
我有一个部署在多个虚拟目录中的 MVC.NET 应用程序。原因是我们在不同的 QA 阶段有不同的版本。
这样做的问题是,在一个站点中 .js 引用用于
/VirtualDir/scripts/file.js
并在另一个网站上
/其他虚拟目录/scripts/file.js
这个问题的另一个方面是我有创建链接的 HtmlHelpers。问题是我的 HtmlHelper 方法中没有 UrlHelper。将 UrlHelper 从视图传递到 HtmlHelper 是否可以?我可以用它来生成标签吗?
还有其他人必须处理此类问题吗?有什么建议吗?
谢谢
戴夫
I'm not sure if I have my question named correctly but here's the issue:
I have an MVC.NET app that is deployed at multiple virtual directories. The reason for this is because we have different versions under various stages of QA.
The problem with this is that in one site the .js references are for
/VirtualDir/scripts/file.js
and on another site it's
/OtherVirtualDir/scripts/file.js
Another aspect of this issue is that I have HtmlHelpers that create links. The problem with this is that I don't have a UrlHelper in the HtmlHelper methods. Is it 'ok' to pass the UrlHelper from the view into the HtmlHelper? Can I get this to generate the tags?
Has anyone else had to deal with these kinds of issues? Any suggestions?
Thanks
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能会考虑创建控制器来返回封装路径的静态内容(css、js 等)的 FileResult。
You might consider creating controllers to return
FileResult
's for static content (css, js, etc) that encapsulates the paths.当从 MVC 中的视图引用文件时,我总是使用它,
因为视图引用与请求它们的资源相关,如果您需要 .JS 文件中的“相对”路径,那么在母版页中使用这段 Javascript 会有所帮助。
最后,CSS 工作得很好,因为 CSS 中的所有路径都相对于 .css 文件的位置。
When making references to files from a View in MVC, I always use this
Since View refferences are relative to the resource requesting them, using this bit of Javascript in your master page can help if you need "relative" paths inside your .JS files.
And finally, CSS works just fine, since all paths in CSS are relative to the location of the .css file.
好吧,最后发现解决方案是这样的:
上面第一个例子的定义如下,
这些 HtmlHelpers 太棒了!
Ok, in the end it turned out the solution is this:
with the following definition for the first example above
these HtmlHelpers are fantastic!