部署后 ASP.NET 网站看起来有所不同
当我使用 Visual Studio 的正常调试功能运行该网站时,很多图像都损坏了,而且格式似乎很混乱。然而,当我部署该网站时,一切似乎都很好。
可能是什么原因?只要看起来部署得很好,就可以安全地忽略使用未部署的网站时出现的格式问题吗?
注意:我对已部署和未部署的网站使用相同的浏览器。
When I run the site using the normal debug feature of Visual Studio, a lot of images go broken and formatting seems messed up. However, when I deploy the site, it all seems fine.
What could be the reason? As long as it looks good deployed, is it safe to ignore the formatting issues that come up with using undeployed websites?
Note: I am using same browser for both deployed and undeployed website.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我的猜测是图像和 CSS 路径。也许他们是相对的?肯定需要更多信息(代码)才能给您可靠的答案。
编辑:解决此问题的一个好方法是在调试时右键单击图像并复制其地址。然后右键单击部署后的图像并复制其地址。比较这两个地址,您可能会发现一些明显的问题,例如路径问题。
My guess would be image and CSS paths. Perhaps they are relative? Definitely need more information (code) to give you a solid answer.
EDIT: A good way to troubleshoot this would be to right click on the image while debugging and copy its address. Then right click on the image when deployed and copy its address. Compare the two addresses and you might spot something obvious like a path problem.
您已部署和未部署的网站的确切路径是什么?
您可能拥有使用仅适用于未部署的网站的路径引用的图像和 CSS 文件。
尝试在运行 Fiddler 时加载已部署的网站,并检查哪些 URL 生成错误。
您究竟如何引用 ASP .Net 源中的图像和 CSS 文件?
What are the exact paths of your deployed and undeployed web sites?
You probably have images and CSS files that are referenced using a path that only works on the undeployed web site.
Try loading the deployed web site while running Fiddler and checking which URLs generate errors.
How exactly are you referencing the images and CSS files in your ASP .Net source?
Mayo 阐述了原因 - 但要回答另一个问题:
不,忽略这些问题绝对不安全,除非您非常清楚地了解它们出现的原因,此时您可以选择不担心它们(尽管我可能不会特别高兴不得不这样做)。
它可能不实用是有原因的,但务实地说,我要求我们可以从版本控制中提取一个项目,构建并运行它,它或多或少应该像实时运行一样(有一些关于满足已安装内容和要求的注意事项)任何必要的配置)-当然我希望外观是正确的。
Reasons are addressed by Mayo - but to answer the other question:
No, it is absolutely not safe to ignore the issues unless you have a very clear understanding of why they arise at which point you may be able to choose to not worry about them (although I'd probably not be particularly happy to have to so do).
There are reasons why it may not be practical but pragmatically I require that we can pull a project from version control, build and run and it more or less should run pretty much as live (there are a few caveats about meeting requirements for installed stuff and any necessary config) - certainly I'd expect the appearence to be right.
我猜你的图像路径中有一些错误。尝试使用例如 Firebug(太棒了!)检查生成的 HTML,看看路径是否错误。
I would guess that you have some errors in your image paths. Try checking the resulting HTML with for instance Firebug(which is awesome!) to see if the path is wrong.
也许就像梅奥说的,也许是这条路。
您是否在路径之前使用〜...例如〜/_images/myImage.jpg或_images/myImage.jpg。
Maybe like Mayo say, probably the path.
Are you using ~ before your path ... like ~/_images/myImage.jpg or _images/myImage.jpg.
大多数情况下,发生这种情况是因为 ASP.NET 开发服务器将您的应用程序作为网站启动,而您可能将其部署在 iis 上的虚拟目录中(作为应用程序)。因此以 / 开头的路径不会以相同的方式做出反应。
正如 Cédric 所建议的,您可以以 ~ 开头您的 url,但前提是您使用的是服务器站点控件(如 asp:image)或带有 runat="server" 的 img html 标记。
对于 CSS、javascript 或任何常规 html,您必须确保所有资源都与页面相关。
I3dx 给出了一个很好的建议,使用 firebug 来跟踪错误的 url。
希望它会有所帮助
Most of the time, it happens because the ASP.NET development server start your application as a website and you probably deploying on iis in a virtual directory (as an application). So path beginning with / will not react the same way.
As suggested by Cédric, you can start your url with ~ but only if you're using a server site control (like asp:image) or an img html tag with runat="server".
For CSS, javascript or any regular html, you must make sure that all your resources are relative to the page.
I3dx give a good suggestion using firebug to track the faulty url.
Hope it will help