locked
Web API, MVC, Account Login With Mobile Device RRS feed

  • Question

  • User45690240 posted

    Hello All

     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 perfectly.

    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 API Methods.

    I hope I explained this correctly, and any help would be greatful .

    Thanks

    Thursday, July 14, 2016 4:47 PM

Answers

  • User-491950272 posted

    Greeting,

    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()
    {
       return View();
    }

    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).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 14, 2016 7:37 PM

All replies

  • User-491950272 posted

    Greeting,

    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()
    {
       return View();
    }

    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).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 14, 2016 7:37 PM
  • User36583972 posted

    Hi PsyChotic,

    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:

    http://www.c-sharpcorner.com/UploadFile/4d9083/how-to-create-web-api-in-Asp-Net-mvc/

    Best Regards,

    Yohann Lu

    Friday, July 15, 2016 4:41 AM