Closed Eilon closed 6 years ago
Thanks for contacting us, @piecho1991. @kichalla, can you please look into this? Thanks!
@piecho1991 You need to reorder the routes in your configuration. In general, routes with more number of segments (in your case 4 vs. 3) should be before the one with less number of segments
Thanks for contacting us. We believe that the question you've raised have been answered. If you still feel a need to continue the discussion, feel free to reopen it and add your comments.
Hi, I believe I am experiencing the same issue.
My routes:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
From what I can tell this issue is related to having Identity being implemented within the project. To test this I created a new application with no authentication and areas/routes work great no problems.
Creating a new project with individual user accounts being added as the authentication results in the routes no longer operating correctly. The result being a URL that looks like this - https://localhost:44396/Admin?area=Admin
Even i am f
Hi, I believe I am experiencing the same issue.
My routes:
app.UseMvc(routes => { routes.MapRoute( name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); });
From what I can tell this issue is related to having Identity being implemented within the project. To test this I created a new application with no authentication and areas/routes work great no problems.
Creating a new project with individual user accounts being added as the authentication results in the routes no longer operating correctly. The result being a URL that looks like this - https://localhost:44396/Admin?area=Admin
Even i am facing exactly same issue, on a sample application url works fine, but as son as I add authentication its breaking, unable to figure out whats going wrong. Just stuck up in our migration to .net core process.
Cshtml code
<a href="@Url.Action("Index", "Story", new { area = "Bio" })" ></a>
html rendered code
<a href="/Bio?area=Bio"> </a>
Routes:
app.UseMvc(routes =>
{
routes.MapRoute(
"Bio_default",
"Bio/{controller}/{action}/{id?}",
new { controller = "Story", action = "Index" }
);
routes.MapRoute(
"default_route",
"{controller}/{action}/{id?}",
new { controller = "Home", action = "Index" }
);
});
Even changing the area route to
routes.MapRoute(
"Bio_default",
"{area:exists}/{controller}/{action}/{id?}",
new { controller = "Story", action = "Index" }
);
isn't changing the behavior. Can someone suggest what could be wrong here. I am banging my head right now. :(
Hi @neesinch,
I had given up on looking for a fix for this. I had a quick look there there this morning and found some documention for core 2.1 - https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/areas?view=aspnetcore-2.1
It looks like you're meant to mark the areas controllers with an area attribte and provide the area name. See my example below. "Admin" is the name of my area. So I have;
[Area("Admin")]
public class AdminPanelController : Controller
{
public IActionResult Index()
{
return View();
}
}
I then setup my routes like so;
app.UseMvc(routes => {
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
Keep in mind that the area route defination has to come first. Then this is what my link off to the area looks like
<li><a asp-area="Admin" asp-controller="AdminPanel" asp-action="Index">Admin Panel</a></li>
I would suspect that your <a href="@Url.Action("Index", "Story", new { area = "Bio" })" ></a>
would also work.
Please don't forget to add the attribute
[Area("Admin")] public class HomeController : Controller { public IActionResult Index() { return View(); } }
Hi, it looks like you are posting on a closed issue/PR/commit!
We're very likely to lose track of your bug/feedback/question unless you:
Thanks!
From @piecho1991 on July 17, 2018 13:48
I have problem with URL-s in ASP.NET Core 2.1 Web Application.
I have used code like below:
and Razor is generating wrong URL not like
http://example.com/Area/Controller/List
buthttp://example.com/Controller/List?area=Area
.My routes configuration:
Copied from original issue: dotnet/core#1796