简体   繁体   中英

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 easy 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?

并不是真正的webby家伙,但是报表中真实文件夹的快捷方式又如何呢?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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