0
votes

this is a simple question and im just asking out of curiosity

ive set up endpoint routing to area as such:

     app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");

            endpoints.MapControllerRoute(
                name: "areas",
                pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            endpoints.MapRazorPages();
        });

and here the controller for the area home page:

[Area("mynewarea")]
[Route("mynewarea/[controller]/[action]")]
public class HomeController : Controller
{

    public IActionResult Index()
    {
        ViewBag.me = "hello world";
        return View();
    }
}

here is the tag helper code in the view

<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
<a class="nav-link text-dark" asp-area="mynewarea" asp-controller="Home" asp-action="Index">mynewarea</a>

this all totally works great but not consistently as i would expect
so for example if i put this in the URL

https://localhost/

it works as expected and i get to the home page
but if i put this in the URL

https://localhost/mynewarea

i get a 404

however if i put this in the URL

https://localhost/mynewarea/Home/Index

i get my page as expected

so:
1. does anyone know why i have to be explicit in my area URLs
2. is there a way to make default area URLs work implicitly, ie as a proper default URL

1
Could you please also share us the code of area controller MyNewArea/Home/Index?itminus
@itminus ah yes thank you for the reminder - updated - and now that ive updated i think i might see that the annotation is causing the restrictiontoy
@itminus deleting the [Route("mynewarea/[controller]/[action]")] annotation makes it worsetoy
deleting the [Route("mynewarea/[controller]/[action]")] annotation makes it worse: I just test that case, but for me I can always get the expected result when accessing https://localhost:5001/mynewarea( using 3.1.100 && 3.1.101). Is there a demo that reproduces the same issue?itminus
@itminus - ok i was running 3.1.0 and when i upgraded to 3.1.1 this problem went away. not sure if was a version issue or if something else happened in the meanwhile - thx for yr helptoy

1 Answers

0
votes

was running aspnetcore v3.1.0
when upgraded to current v3.1.1 problem went away