Using regular js, you can use this in your layout.htmlcs, at the beginning:
@{ <script> sessionStorage.setItem("ProductionHostURL", '@System.Configuration.ConfigurationManager.AppSettings["ProductionHostURL"]'); </script> } <!DOCTYPE html>
Then in your main js file layout.htmlcs you can use this method similar to this:
var urlBaseProduction; var urlBaseDevelopment; $(document).ready(function () { configureHostEnvironment() .... }
In this method, configure the variables for use in production and development, for example:
function configureHostEnvironment(){ HOST = sessionStorage.getItem("ProductionHostURL") if (HOST.length <= 0) { alert("Host not configured correctly") } else { urlBaseProduction= host + '/api/'; urlBaseDevelopment= host + port + '/api/'; } }
If you have a suggestion or improvement on this method, please comment.
source share