Open brower from API

ANB 181 Reputation points
2022-09-29T14:45:25.123+00:00

My customer calls my Net Core API passing some parameters and after run those, I need to open a browser on his/her computer with some html returning from the API call.
How can I do it ?

Thx

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,149 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,382 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 47,806 Reputation points
    2022-09-29T15:59:29.353+00:00

    You cannot do that. An API has no UI and is not even being called by a browser necessarily. Opening the browser has to be done by the code that calls your API. What you should probably do is identify the URL that you want the client to navigate to. Whether that is part of your existing data or passed as an HTTP header depends on what you're doing. Nevertheless the client that called your API is then responsible for opening a browser window to that URL. Your API cannot do that itself.

    0 comments No comments

  2. ANB 181 Reputation points
    2022-09-29T16:20:17.097+00:00

    Even though this API run on Net 6 ?
    I thought somehow my API could have API Controllers but also MVC Controllers.
    Adding services.AddControllersWithViews() and also dependency services.AddTransient<MyMvcController, MyMvcController>() in program.cs

    Then the API Controller would call the MVC Controller and the MVC present its View.