12

I've successfully used the EmberJS JavaScript framework with an ASP.NET web application, by referencing ember.js file.

I'm under the impression that Ember-CLI is the way Ember will be heading in future versions.

If this is correct, what's the appropriate way to keep using Ember going forward? Does it make sense to use Ember-CLI with ASP.NET, or is the assumption that the client is only ever static HTML and CSS/JS that calls back to server-side code (eg. WebAPI)?

David Gardiner
  • 16,892
  • 20
  • 80
  • 117
  • I am not seeing any big difference between Ember-Cli and Typescript. TypeScript is more useful definately. What Ember-Cli is trying to achieve is same as you would use Typescript, Grunt-Cli – Amit Feb 20 '15 at 05:50
  • Funny that you mention TypeScript - I am actually using that too, but it hadn't occurred to me that it was relevant to the question – David Gardiner Feb 20 '15 at 06:03
  • Agree that it may not be relavant to question but I was just trying to clear it by base fucntionality. I think there is no cause for worry :-) . You can use Ember with ASP.NET as you are using currently. Only thing which need understanding is composition and configuration part for build ,deployment and dependency management. So, either use known tools separatly or use single tool which serve as wrapper to others. – Amit Feb 20 '15 at 06:21
  • I don't see a reason why you couldn't do either, but I think a lot of people like to keep the frontend separate from the API which would work just fine for .NET applications. – Dhaulagiri Feb 20 '15 at 16:47

1 Answers1

16

Ember-Cli is just the command line toolchain that the Ember community is "blessing", so it's really just a different way of building the ember app.

I'm actually using Ember-Cli with ASP.NET MVC and WebApi. Essentially what I'm doing is using EmberCLI to output an index.html file (ember new myapp sets up a project to do this by default), and then having my MVC app route to an /App url, where the controller returns a View("~/whateverdirectory/myapp/dist/index.html"); Razor doesn't care that the view you return isn't a .cshtml file, so this works fine, particularly if you're using Ember to control the whole page. This way you can use the standard authentication in ASP.NET, and then when the user is logged in, send them to the App controller's index route through MVC, and serve them the Ember app.

Update 8/18/2015

I've added some sample code on github.

Ryan Hayes
  • 5,290
  • 4
  • 42
  • 52
  • Would this work if you needed different levels of privileges of users of the app? – Adam Knights Jun 03 '15 at 15:53
  • 1
    The way you'd do it is set the [Authorize] attributes on your web api methods. Since it's inside the context of an ASP.NET app, you get all the security that you normally would with webapi. – Ryan Hayes Jun 29 '15 at 13:06
  • Could you please share a sample code of your controller? I'm not getting this to work... – Lopo Aug 18 '15 at 09:39
  • I added a link in my answer to some sample code in a gist on github. Let me know if that helps you. – Ryan Hayes Aug 18 '15 at 19:14