How to create a one-page application (SPA) using ASP.NET MVC and form authentication?

I use Knockout for view modes l with external templates and sammy for routing and web APIs to retrieve data from the server.

Problem

  • How can I use server routing to redirect the user to client-side routing, for example, people / username for # / people / username.

  • Also there is a lot of confusion about user authentication?

  • How to authenticate a user in a single-page application?

  • Are there some pages that can be viewed without logging in? how to achieve this?

Can I use a partial view of the result from the controller and the selection in the view?

+4
source share
2 answers
  • Custom routing , but be warned that getting data from a client will be confusing if you ever need to.
  • It should be the same authentication type that you are used to. [Login] , as always.
  • The application will be authorized upon initiation, the โ€œSeparate Pageโ€ part will not affect this, except that you must be careful to check the user rights for each AJAX request .
  • the authorize attribute can be placed at the class (controller) level, as well as at the method (action) level, so you can selectively with it as needed.
  • Partial viewing of results and AJAX can be misleading. Basically, you create the server side of an AJAX request under normal conditions if you want it to work.

Finally, you may be in your head trying to do this. Microsoft ASP.NET is a very thick technology for the Internet. I know this deeply, and yet I would say that I can create a one-page application much faster in many other technologies. Add to this that I get the impression that you are pretty new to ASP.NET, based on the types of questions you ask, and this will be a serious problem for you.

Good luck. And read this book . This is an older technology, but I have never found a better book for teaching best practice. Steve Sanderson is a genius.

+4
source

use both url routing, such as sammy, and server-side routing, view views through ajax and authenticate through the controller.

+1
source

Source: https://habr.com/ru/post/1437174/


All Articles