Vijayant Katyal
Vijayant Katyal

Reputation: 662

How to Create Single Page Application (SPA) using ASP.NET MVC and Form Authentication?

I'm Using Knockout for view modesl with external templates and sammy for routing and Web API for fetching Data from server.

The Problem is

  1. how can i use server routing to redirect user to client side routing e.g people/username to #/people/username.

  2. Also there is a big confusion in authenticating user ?

  3. how to authenticate user in single page application ?

  4. there are some pages which can be viewed without login ? how to achieve that ?

Can i Use Partial View Result from Controller and fetch on view ?

Upvotes: 4

Views: 2701

Answers (2)

Vijayant Katyal
Vijayant Katyal

Reputation: 662

use both url routing like sammy and server routing , load views via ajax and authenticate via controller .

Upvotes: 1

deltree
deltree

Reputation: 3824

  1. Custom Routing, but be warned that getting the data from the client is going to be confusing if you ever have to do it.
  2. Should be the same type of authentication you're used to. The [Authorize] attribute as always.
  3. The application will authorize on initiation, the "Single Page" part doesn't affect that, except that you must be careful to check the user's permissions on every AJAX request.
  4. The authorize attribute can be placed at the class (controller) level as well as the method (action) level, so you can be selective with it as needed.
  5. Partial View Results and AJAX can be confusing. Basically, you're building the AJAX request server side under normal conditions if you want to make it work.

Finally, you may be in over your head trying to do this. Microsoft's ASP.NET is a very thick technology for the web. I know it intimately and still I would tell you that I can build a single page application much quicker in a lot of other technologies. Add to that that I get the impression you're fairly new to ASP.NET based on the types of questions your asking and this will be a major challenge for you.

Good luck. And read this book. It's older technology, but I've never found a better book for teaching good practices. Steve Sanderson is a genius.

Upvotes: 4

Related Questions