Can an API be built with ASP.NET web application?

Donald Symmons 2,856 Reputation points

Hello Community, From the tutorials I have been seeing it looks like APIs are built only if an application is created with MVC. But is it possible to build an API with ASP.NET web application? And how do I go about from start? Thank you

Microsoft Technologies based on the .NET software framework.
3,346 questions
A set of technologies in the .NET Framework for building web applications and XML web services.
3,247 questions
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 25,391 Reputation points Microsoft Vendor

    Hi @Donald Symmons,

    ASP.NET web applications have a dedicated ASP.NET Web API project that can be seen when you create the project from VS. Below is a tutorial for getting started. User's image

    Best regards,
    Lan Huang

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

1 additional answer

Sort by: Most helpful
  1. Albert Kallal 4,646 Reputation points

    You are free to build/create a specific web api project, and in near ALL cases, one is free to simple add web API (end points) to an existing WebForms site.

    You can create a 100% separate web method page (a asmx page), or you can even add web methods to existing web pages. So, say this web page and a web method (that is a API web end point).

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub
        Public Shared Function MyHello() As String
            Return "Hello World"
        End Function

    So, the above web method? it will support a SOAP call (xml), a REST call, or better yet, a standard ajax call (and without any changes also supports JSON). So, in the markup, we can have this (we assume you have jQuery installed).

                <asp:Button ID="cmdTest" runat="server" Text="Web API test"
                    OnClientClick="endpointtest();return false;"
                    function endpointtest() {
                            url: "TestAPI.aspx/MyHello",
                            dataType: "json",
                            type: "POST",
                            contentType: "application/json; charset=utf-8",
                            data: {},
                            success: function (data) {
                                alert("return value = " + data.d)
                            failure: function (rData) {
                                alert("error " + rData.d);

    So there is little stopping you from adding web endpoints to a existing webforms site, and there is full support as such.

    Above when run results in this: User's image

    0 comments No comments