Asp.Net MVC relatives paths for two application pointing to same code base -


hi have confusion publishing application on 2 server. path both like:- http://www.myapp.com/ , http://www.myapp2.com/myapp/

so including script, css or images, have given 2 path like:-

   <img src="~/images/ajax-loader.gif" alt="loading" />  ,    <img src="~/myapp/images/ajax-loader.gif" alt="loading" /> 

is there way not need put scripts twice. have tried:-

  <img src="./images/ajax-loader.gif" alt="loading" /> 

this works how , why not sure. please explain or give other suggestion.

thanks

the ideal solution relative path problems in asp.net mvc applications use of t4mvc packages. t4mvc package becoming standard handle relative path , magic strings in mvc applications.

  • install t4mvc nuget in mvc application

install-package t4mvc

  • once installed, able see t4mvc.tt file in solution.
  • right-click, , "run custom tool"
  • this should create constants static resources in application.

once done, able access resources follow:

<img src="@links.content.images.ajax_loader_gif" alt="loading" /> 

and yes, don't need type-in, intelli-sense provide resources select.

one small thing, may need move images "content" folder in application, because far aware, t4mvc doesn't create constants folders (except, content, scripts, , bundles). yes, standard put images in content folder.

talking benefits - - don't need worry deployment path. (which original concern) - also, creates constants views, controllers , actions in application (along images, scripts, bundles, etc), , way can rid of magic strings.

more t4mvc - https://github.com/t4mvc/t4mvc/wiki/documentation


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -