Last post Jul 15, 2016 04:41 AM by Yohann Lu
Jul 14, 2016 04:47 PM|PsyChotic|LINK
Let me see if I can explain this as best I can, I am fairly new to writing Web API applications, much of my work has been web based. I have built a regular web application that communicates with a SQL Server Database. I use Active Directory to Authenticate,
(Company Users). I pass that information, to the Identity Model system, to have the user saved to the database, with their UserName and Password(Hashed). This is code I have developed in the Account Controller via the Login ActionResult Method, which works
What I have been tasked with now, is being able to allow users to Login via a mobile Device(Android), to the same Web Application, I think this is where the Web API comes in, can I use the same Login ActionResult Method as I do for the Web Login portion,
in the Accounts Controller, or do I write a separate Login ActionResult Method in the Accounts Controller and make a Posts to the server to Authorize the user, Or do I construct a separate API Controller and implement a second Login mechanism using the Web
I hope I explained this correctly, and any help would be greatful .
Jul 14, 2016 07:37 PM|Janshair Khan|LINK
If you are using MVC 5 (Or preceding), you have to create a separate project for building API(s). In ASP.NET Core, they are united. In Web API(s), there is no view, instead you have to decide that whether you want to output JSON or XML and most of the code
logic is the same. But the core action functionality differs such as for MVC it is like
public ActionResult Login()
in Web API, it is like:
public IEnumerable<string> Get()
return new ["Person 1", "Person 2"];
All the CRUD logics are the same. You just need to understand HTTP verbs and request\response in a little bit.
For security, the Authentication and Authorization process is a little bit different. You can get the information from
here. To learn more about it. Here is a good Windows Authentication example for securing API(s).
Jul 15, 2016 04:41 AM|Yohann Lu|LINK
can I use the same Login ActionResult Method as I do for the Web Login portion,
As Janshair said, the difference between Web API and MVC are very small. You can make some adjustments to achieve your needs. You can also create a Web API in your own applications (MVC).
You can refer the following tutorials and make a test on your side.
How to Create Web API in ASP.Net MVC: