简体   繁体   English

Page.ResolveUrl()在VS2010 Dev Server上不起作用

[英]Page.ResolveUrl() not working on VS2010 Dev Server

I'm trying to use an existing, old, ASP.Net web application that will serve as the main UI for our project. 我正在尝试使用一个现有的旧ASP.Net Web应用程序作为我们项目的主要UI。 The web application employs MANY user controls, with a lot of: 该Web应用程序使用许多用户控件,其中包括:

<element attribute='<%=Page.ResolveUrl("~/path/to/resource")' ...

I have a problem, however. 但是,我有一个问题。 If the application is deployed to IIS, these calls to Page.ResolveUrl() work fine. 如果将应用程序部署到IIS,则对Page.ResolveUrl()的这些调用可以正常工作。 But if I try to run this application in Visual Studio Development Server, it does not resolve any URLs (ie, no styles applied, no images rendered, etc.) 但是,如果我尝试在Visual Studio Development Server中运行此应用程序,它将无法解析任何URL(即,未应用任何样式,未呈现任何图像等)。

// If deployed in IIS, the style tag renders like this (and works):
<link href="/adminconsole/styles/styles.css" ...

// On the VS Dev Server:
<link href="/styles/styles.css" ...

What I want, is for these calls to "just work" no matter if the application is deployed to IIS, or is running on the Visual Studio Development Server. 我想要的是,无论应用程序是部署到IIS还是在Visual Studio Development Server上运行,这些调用都“正常工作”。

Some pertinent info: 一些相关信息:

The web app does not use a master page. 该Web应用程序不使用母版页。 It includes the header as a user control :( 它包括标题作为用户控件:(

The VS Dev web server is usually having only one site and accessing on localhost with a certain port number. VS Dev Web服务器通常只有一个站点,并且使用特定端口号访问localhost。 Check project properties in web tab and see if you can change that Url to have a site name like you have in IIS. 在“ Web”选项卡中检查项目属性,然后查看是否可以更改该“ URL”以使其具有与IIS中相同的站点名称。 If not possible and if you are not willing to change the code make your developers to use local IIS or IIS express instead of that little VS toy. 如果不可能并且不愿意更改代码,则使您的开发人员使用本地IIS或IIS Express而不是那种小的VS玩具。

In my experience is anyway much better to develop and test on IIS because you work in a more similar to production environment and if any, you discover issues earlier so have more time to react not last night before go live. 以我的经验,在IIS上进行开发和测试总会更好,因为您在与生产环境更相似的环境中工作,如果有的话,您会发现问题较早,因此有更多时间在上线之前没有做出反应。

I had to do something like this very recently but instead of using <%=ResolveURL("~/path/to/file")%> I used <%=ResolveURL("relative/path/to/file")%> try that to see if that works. 我最近不得不做类似的事情,但是我没有使用<%=ResolveURL("~/path/to/file")%>而是使用了<%=ResolveURL("relative/path/to/file")%>尝试看看是否可行。 It worked for me. 它为我工作。

I also think that testing/debugging on local IIS is definitely better. 我也认为在本地IIS上进行测试/调试绝对更好。 Remember, Cassini (the toy web server that ships with VS) runs under the developer's credentials so permissions to the local file system are very different compared to running your website on IIS directly. 请记住,Cassini(VS附带的玩具Web服务器)在开发人员的凭据下运行,因此与直接在IIS上运行网站相比,对本地文件系统的权限有很大不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM