I have a MVC 4 web app (http://whatever/myapp/home/someprocess
) running under the default web site (on the server) as a separate application and in various places i need to reference files starting at the root mostly in javascript (root = http://whatever/myapp/
).
The window.location options in this answer amongst others doesn't work for me as it gets the base url i.e. http://whatever/
instead of http://whatever/myapp/
.
Extract from the answer above:
• window.location.host : you'll get sub.domain.com:8080 or sub.domain.com:80
• window.location.hostname : you'll get sub.domain.com
• window.location.protocol : you'll get http:
• window.location.port : you'll get 8080 or 80
• window.location.origin : you'll get http://sub.domain.com
The reason I do not want to manually append the "myapp" part is that i need to change this everytime i run it in express debug mode. Surely I'm missing something simple?
When debugging on my pc it should then implement http://localhost:someport/home/someprocess/
and when publishing to a server it should implement http://server/myapp/home/someprocess
.
A line of code I'm currently battling with:
var jqxhr = $.getJSON("/myapp/AutoComplete/LoadComboData", { classname: '@ViewBag.ClassName', functionname: '@ViewBag.MethodName', searchstring: value, context: contextvalue, assembly: '@ViewBag.AssemblyName' })
@*var jqxhr = $.getJSON("/AutoComplete/LoadComboData", { classname: '@ViewBag.ClassName', functionname: '@ViewBag.MethodName', searchstring: value, context: contextvalue, assembly: '@ViewBag.AssemblyName' })*@
As you can see when debugging in VS2013 I comment out the top one, and when the app gets deployed I have to make sure the bottom one is commented out. There HAS to be a better approach?