lundi 21 avril 2014

ASP.net - puis-je utiliser une balise de base HTML pour résoudre un répertoire virtuel ? -Débordement de pile


I have an ASP.NET MVC web application running in IIS as a subweb; let's say its path is something like http://mysite.com/subweb.


I have a view which serves content obtained from a CMS. The CMS editor has entered some content containing a relative image path <img src="/images/imga.png" />.


This works fine on the production server where the site is the root website, but not on the staging server where the site is a virtual directory under the root website


The path should be <img src="/images/imga.png" /> on the production server


and <img src="/subweb/images/imga.png" /> on the staging server.


Is it possible to use the <base> tag to resolve this image path?




<head>
<base href="http://mysite.com/subweb/" />
</head>

<html>
<body>
<img src="/images/imga.png" />
</body>
</html>



It doesn't seem to work. Can anyone explain why or if this is a workable approach? I don't want to require the content editor to have knowledge of the website deployment option (which changes between UAT and production).




Try


   <img src="images/imga.png" />

to make it a relative URL. Of course it's not that easy, the content editor must be changed. But I do believed that is the problem. URLs starting with a / are resolved from... (wonders) the domain's top-level directory?




The base tag only affects relative URLs. Try changing your image tag to this:


<img runat="server" src="~/images/imga.png" />

This will work even in sub directories of your app. .Net will resolve the "~/" to your application root.



I have an ASP.NET MVC web application running in IIS as a subweb; let's say its path is something like http://mysite.com/subweb.


I have a view which serves content obtained from a CMS. The CMS editor has entered some content containing a relative image path <img src="/images/imga.png" />.


This works fine on the production server where the site is the root website, but not on the staging server where the site is a virtual directory under the root website


The path should be <img src="/images/imga.png" /> on the production server


and <img src="/subweb/images/imga.png" /> on the staging server.


Is it possible to use the <base> tag to resolve this image path?




<head>
<base href="http://mysite.com/subweb/" />
</head>

<html>
<body>
<img src="/images/imga.png" />
</body>
</html>



It doesn't seem to work. Can anyone explain why or if this is a workable approach? I don't want to require the content editor to have knowledge of the website deployment option (which changes between UAT and production).



Try


   <img src="images/imga.png" />

to make it a relative URL. Of course it's not that easy, the content editor must be changed. But I do believed that is the problem. URLs starting with a / are resolved from... (wonders) the domain's top-level directory?



The base tag only affects relative URLs. Try changing your image tag to this:


<img runat="server" src="~/images/imga.png" />

This will work even in sub directories of your app. .Net will resolve the "~/" to your application root.


0 commentaires:

Enregistrer un commentaire