How can I make angular include sub-folder in the URL ?
By never hardcoding the url in your application but using a server side url helper to generate it:
<script type="text/javascript">
var url = '@Url.RouteUrl("DefaultApi", new { httproute = "", controller = "controllerName" })';
$.post(url, { foo: 'bar' }, function(result) {
...
});
</script>
Alternatively you could use this helper in order to embed the correct url in some DOM element of your SPA. Suppose that you are AJAXifying an anchor. You would simply generate the proper url on the server:
<a href="@Url.RouteUrl("DefaultApi", new { httproute = "", controller = "controllerName" })" id="mylink">Click me</a>
and then in your separate js file:
$('#mylink').click(function() {
$.post(this.href, { foo: 'bar' }, function(result) {
...
});
return false;
});
Notice how an url is never hardcoded anywhere. It is guaranteed to be correct because it is generated by a server side url helper taking into account your routes configuration and any possible virtual directories.