angular and servicestack in .net – changing the root path is a nightmare

angular and servicestack in .net – changing the root path is a nightmare

OK – first, it is because all these great tools are assuming the root url is /. They all give part of the picture, but they don’t know the whole story. Neither do did I. But do I google root uri, base url, AHHHH! Anyways, lets document this so I don’t and you don’t have to go nuts and google for hours like I did.

First – I am using ServiceStackVS 4.x, and it is an angular (not MVC – that might be a mistake) app.  I want

  • myweb.com/myApplication/myServices for the services and
  • myweb.com/myApplication for the application.

So for ServiceStack (I installed the extension ServiceStackVS into Visual Studio 2013) …

  • – change the web.config line from a “*” to “myApplication/myServices*” in the lines that look like:

<br data-mce-bogus="1">

<httpHandlers>
<add path="myApplication/myServices*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
<;/httpHandlers>;

 

  • Then add the HandlerFactoryPath to look like (in AppHost.cs)
</pre>
SetConfig(new HostConfig
{
DebugMode = AppSettings.Get("DebugMode", false),
AddRedirectParamsToQueryString = true,
HandlerFactoryPath = "myApplication/myServices"
});
<pre>

Now for the angular/web part

  • edit all the templateUrl: items to NOT have a / at the front. So all the /partials become partials
  • in all your controllers.js – you have to remove the / and add the myServices so for example, the default hello example on the web … $http.get(/hello/ becomes $http.get(myServices/hello/
  • default.cshtml now edits
    • all the href links and add a <base href=”/docSnibbets/” /> in the <head> section quite near the top (after title and before anything useful happens).
    • all the src attributes to REMOVE the /
      • in the <head>
      • AND (important) in the <body> sections

Is this the final server (eg are you publishing?) add the npm stuff…

  • on the publish server – do you see a node_modules folder after you publish? Likely not.
  • SOOOO . install nodejs on the target computer to which you are publishing to
  • go to the inetpub/…../myApplication directory and type “npm install”
    • it looks at the package.json file and does all the magic for you

The main project’s properties

  • edit the main project’s properties
    • click on the Web tab in Visual Studio
    • add /myApplication to the end of the ProjectUrl so it becomes http://localhost:28032/myApplication
    • copy this to the CHECKED Override application root URL
      • http://localhost:28032/myApplication
    • Now … change the port by adding one ***THIS IS THE IMPORTANT BIT ***

AHHH! It finally works (assuming you set the permission properly 🙂 )

ELB Solutions.com Inc.
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.