开发者

ASP.NET inner directory virtual path root

I have two separate web applications named MainWeb and Reports. I want to deploy them this way: there would be one virtual application for MainWeb, pointed, for instance, to c:\inetpub\www\mainweb.

The Reports application I would like to deploy in a subdirectory of main web, so that it is at c:\inetpub\www\mainweb\reports.

Thus I can combine the two which are logically coupled but I want to have them in separate projects for e开发者_StackOverflow中文版asy manipulation.

The problem is, in my Reports project I use constructs like ~/Style/Whatever.css which works fine when running standalone Reports application but when using as subdirectory in main web, it resolves to http://localhost/Style/Whatever.css though I would need it to resolve to http://localhost/reports/Style/Whatever.css.

So the question is, is it possible to handle this situation, maybe some way to modify the behavior of ~ in nested web.config?


Not really a webby guy, but how about a shortcut to the real folder in reports?


hm, I have similar situation and I am not sure what's your problem, VirtualPathUtility and server control resolves ~ to current web application root.

But maybe you can put Virtual Path in Properties/Web section of your Reports application directory for localhost, picture here


There are 3 different ways I've solved this problem before:

  1. Move your style references from the "Report" app up to the "MainWeb" app. This way your "~" url references will still work. You can use another virtual directory to link your resource folders in under the root if you don't want to move the actual files.
  2. Create a static helper property called "ApplicationPath" that will return either "~/" or "~/Reports" depending on where it is being hosted. Then you can just use this property to return the correct url for your resource when you are building the HTML.
  3. Use embedded resources. With the embedded resources, the URL is automatically generated for you so you don't have to worry about the paths.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜