Search code examples
c#.netasp.net-corepostman

Testing .NET 6 app configured with identity using postman


I have a .NET 6 application that is configured to use identity for authorization and would like to test other controllers in the application. I've tried using postman but the request keeps returning a 404 error.

enter image description here

I tried using postman interceptor to capture the credentials from the request but could not figure out how to use them.

enter image description here

I also tried setting up the app to use cookies but nothing seems to be happening.

builder.Services.ConfigureApplicationCookie(options =>
{
    options.LoginPath = "/Account/Login";
    options.AccessDeniedPath = "/Home/AccessDenied";
});

Solution

  • Do you add below code to your Program.cs?

    builder.Services.AddControllersWithViews();
    ...
    app.MapControllerRoute(
        name: "default",
        pattern: "{controller=Home}/{action=Index}/{id?}");
    

    You can have a look at Routing to controller actions in ASP.NET Core to know more.

    Try to add the above route for mvc.

    result: enter image description here