Reputation: 1126
I created a new simple controller But when I enter the following address in the browser, could not find it!
http://localhost:5000/Test/Index
Test.cs:
using Microsoft.AspNetCore.Mvc;
namespace Test.Controllers
{
[Route("[controller]/[action]")]
public class TestController : Controller
{
[HttpGet]
public IActionResult Index()
{
return Content("Welcome");
}
}
}
Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
namespace Test
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddRazorPages().AddRazorRuntimeCompilation();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
}
}
}
Where did I do the wrong thing?
Upvotes: 0
Views: 249
Reputation: 5215
first Edit your Controller attribute :
[Route("[controller]/[action]")]
to
[Route("[controller]")]
and
try this
app.UseEndpoints(endPoints =>
{
endPoints.MapControllerRoute(
"default",
"{controller}/{action}/{id?}");
});
also make sure you are using correct port 5000 or 5001 are defaults
Upvotes: 2