So – again Learning AngularJS is an AWESOME BOOK (Kindle version has clickable links). This was my 2nd book – as I read another AngularJS book that was SUPER LONG and then I had downloaded another (to one to the right) which was quite cheap – and left it. Apparently this “cheap book” was the ticket to SUPER SUCCESS. Thanks for writing the book in his “here do this” and “this is why we did that” style. And his backup websites and fiddler examples – SOOO COOL to learn that way.
BUT – it worked when you went to “play” it in Visual Studio 2013, but when I went to publish it, as usual the wheels fell off the bus. Here is the last chapter of that book “Publishing this whole mess onto a real website”. Can all of the readers comment this so we can all make it better? I will contact the author and ask if he can plagiarize all this material (and I hope all your comments) this into his book as a new chapter. Maybe he will re-write it for Angular 2.0!? I am writing it in bullet form and if the author wants I can make it nice. Please plagiarize this article – it will prevent much hair ripping. I DID give advice NOT to use MS products when you do your own apps – but I didn’t listen to myself – at least I feel quite proud that I did it.
Prepping the output directory
- a) there are 2 projects. Publish the .Web project (main one) to myDirectoryOnTheWeb and publish the .WebServices project to myDirectoryOnTheWeb/api .
- ONLY MAKE THE myDirectoryOnTheWeb an app in IIS (proof is all my hair ripping and this article). The services will “just work” if you plain publish them and no config in IIS. My main issues was all the web.config stuff below that was not explained in detail. I hope he edits his book.
- change your home controller to ADD the following method which overwrites the default redirect when you have not logged in (authenticated) from its default ~/login?redirect=/ to something like ~/myDirectoryOnTheWeb/login=redirect=/myDirectoryOnTheWeb
Add it to the HomeController.cs file (here are my heros)
[c language="#"]
public override string LoginRedirectUrl
{
get
{
//http://w3facility.org/question/servicestack-authfeature-htmlredirect-being-ignored/
var appUrl = HttpRuntime.AppDomainAppVirtualPath;
appUrl = appUrl.TrimEnd('/');
return appUrl + "/login?redirect={0}";
}
}
[/c]
- Change the ...Web project's web.config to look like this so the root will not be referenced. (I don't think we need to modify the ...WebServices project)
[c language="#"]
<location path="myDirectoryOnTheWeb/api">
<system.webServer>
<handlers>
<add path="myDirectoryOnTheWeb/api" name="ServiceStack.Factory" type="ServiceStack.WebHost.Endpoints.ServiceStackHttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true" />
</handlers>
</system.webServer>
</location>
[/c]
also
[c language="#"]
<system.webServer>
<!-- ServiceStack: Required -->
<validation validateIntegratedModeConfiguration="false"/>
</system.webServer>
[/c]
and
[c language="#"]
<system.web>
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="Off" />
<httpRuntime targetFramework="4.5" />
<httpHandlers>
<!-- Added here due to <a href="http://mono.servicestack.net/ServiceStack.Hello/" target="_blank">http://mono.servicestack.net/ServiceStack.Hello/</a> -->
<add path="api*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
</system.web>
[/c]
- My heros on the above topic
- use lots and lots of generic functions to NOT use hardcoded names I found these helpful
- c# helpful commands
- var appUrl = HttpRuntime.AppDomainAppVirtualPath;
- string dataDir = ConfigurationManager.AppSettings.Get("AbsoluteDataPath").TrimEnd('/').Replace("~/","") + "/";
- string mappedfileDownloadRoot = HttpContext.Current.Server.MapPath(fileDownloadRoot);//http://www.dotnetperls.com/mappath
- angularJs useful chunks of code to un-hardcode the web root
- add an angular.constant portion and use it again and again
- .constant('myAppConstants',
{
serviceStackRootStartingWithSlash: '/myDirectoryOnTheWeb/api'
, dataDirectoryRelativeToAppRoot: 'data'
}
);
- .constant('myAppConstants',
- var urlToDownloads = $location.protocol() + '://' + $location.host() + portParm +'' + myAppConstants.serviceStackRootStartingWithSlash + '/download/' + file; //TODO: make this a function in the future
- add an angular.constant portion and use it again and again
- c# helpful commands
- Compile Settings. The app discussed in the book has 32bit stuff in it. Therefore - in all places - put the compile settings to "Any CPU".
- Do NOT use the 64bit IIS Express (I assume you have not if you are reading this far)
- In Visual Studio 2013 Express - Build->Batch Build - look at the settings - to change these in ways you are more familiar - go to the ...Web and ...WebServices and choose Project -> ... Properties and set everything so that the Build->Batch Build screenshot looks like the one below
- my heros are:
- http://stackoverflow.com/questions/4657087/system-badimageformatexception-on-running-servicestack-examples (this is the revelation that some of the code is 32 bit)
- Did you know there was a 64bit version of IIS Express from VS2013? Don't use it for this project but ... there is!
- http://stackoverflow.com/questions/11370344/could-not-load-file-or-assembly-an-attempt-was-made-to-load-a-program-with-a
- IIS
- In the AppPool that you use - TURN ON THE Support for 32 Bit under the AppPool's advanced properties/settings - THIS IS THE MAGIC
- Stop and Start your AppPool
- Another helpful suggestion is to create a local publish so
- use the "play" button in VS to get up and going
- publish locally and to a non-root location to work all those bugs out
- publish to the real place - assuming a non-root location
Other links to understand the auth part of ServiceStack.
- https://github.com/ServiceStack/ServiceStack/wiki/Authentication-and-authorization
- http://tiku.io/questions/251003/when-servicestack-authentication-fails-do-not-redirect
- http://idevexplorer.com/2014/11/servicestack-net-developing-authentication-module-using-auth0-and-oauthprovider-to-login-using-gmail-twitter-facebook-account/
- http://stackoverflow.com/questions/15654994/servicestack-basic-authentication-htmlredirect-is-not-respected-by-mvc-servicest
- https://github.com/ServiceStack/ServiceStack/wiki/Sessions
- http://stackoverflow.com/questions/13065289/when-servicestack-authentication-fails-do-not-redirect
Thanks for the post, I will try to look into it more and give you some feedback when I get a breather 🙂 .
I totally understand. Again – if you peruse it, I will make it “more complete” as per your suggestions and the availability of my breathing room (I read between the lines of your comment – life is quite busy). Just so you know, my breathing room became MUCH larger since you put such a nice boilerplate and explanation together in your book. I was lightly panicking until I read your book because I don’t have time learn this new tech the hard way (trial and error). Thanks again – no pressure.