I am trying to call controller action in subfolder located in main Controller folder. I changed RoutePrefix in controller and app.MapControllerRoute() in program.cs different ways. But my postman call still not hitting my target action in controller. I am looking a suitable solution.
program.cs as follows.
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
.AddNegotiate();
builder.Services.AddAuthorization(options =>
{
// By default, all incoming requests will be authorized according to the default policy.
options.FallbackPolicy = options.DefaultPolicy;
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
}
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseAuthentication();
app.UseAuthorization();
app.UseCors(x => x
.AllowAnyMethod()
.AllowAnyHeader()
.SetIsOriginAllowed(origin => true) // allow any origin
.AllowCredentials());
app.UseRouting();
app.MapControllerRoute(
name: "default",
pattern: "api/{controller}/{action}/{id}");
app.Run();
My CommonController.cs as follows.
namespace AppWebSerivce.Controllers.CardDetails
{
[RoutePrefix("api/CardDetails/Common")]
public class CommonController: ControllerBase
{
[HttpPost]
[Route("v1/GetStringName")]
public string StringName()
{
string ss = "SS";
return ss;
}
}
}
My Postman call as.
http://localhost:5150/api/CardDetails/Common/v1/GetStringName
Controller path as.
AppWebSerivce -> Controllers -> CardDetails -> CommonController.cs
I am trying to hit controller action in Controllers -> CardDetails -> CommonController.cs using RoutePrefix.
