0

I have made a new project using the ASP.NET Web Application template in Visual Studio 2015. Then I selected MVC and Individual User Accounts to specify the template further. The solution I got is complete in that it offers me all the web pages you need for account management such as registering and logging in.

However, now I want to hook in a Xamarin.Forms mobile client to this account management scheme. I am making a native UI to register users, instead of redirecting them to a webpage or webview. I want to send user registration data, such as username and password, from this UI to the server so it will create an account. This means that I don't want to use the webpages offered by my MVC app, but rather send the registration data to the server and have it create an account, notfifying me of succes or failure.

I am anticipating that I would need to either use HTTP POSTs to login and registration endpoints in the AccountController or implement a public API. However, doing a post will return a webpage, and my client is not interested in a webpage.

I think one of the above should be possible to implement quite easily, but I am having a hard time searching for answers or methods, since I don't know how to phrase my problem properly, and with the abundance of guides on MVC, all my results are muddied.

Is my idea of this being possible flawed or have I missed a fundamental concept of MVC? What are the steps I should take in order to make this possible?

Zimano
  • 1,870
  • 2
  • 23
  • 41

2 Answers2

1

One misconception is that doing a POST will return a webpage. You can return any type of content from an MVC controller. But your account registration endpoints should be Web API controllers that return JSON. That JSON can be as simple as containing a boolean that indicates if the action was successful or not.

You do not need to use MVC at all. You can completely do away with the account controllers and views that the template created for you. Just copy the code that you need from the MVC controllers into your Web API methods.

You're right, this is quite easy to do.

Clint B
  • 4,610
  • 2
  • 18
  • 22
  • 1
    I've found this guide that looks promising. I think `Web API` is the keyword here. http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api Thank you for your answer, and I believe that is exactly the way I am going to do this. I will try and if this works, I can accept your answer :) – Zimano Jun 21 '16 at 11:29
  • I implemented a web API, and my client now successfully receives tokens after registering using a JSON request. – Zimano Jun 21 '16 at 15:37
  • Good to hear! I don't know why someone down voted your question. I up voted it. – Clint B Jun 21 '16 at 15:52
0

I think, You can use ASP.NET Web API for doing this task. On server, you host your API for registering the users as well as logging into some client application.

Now, You need to consume this API in a client application. The client application could be a Console application, Windows application or a Web application. There are lots of tutorials about making an Web API on official ASP.NET site.

vivek
  • 1,595
  • 2
  • 18
  • 35