You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Repository navigation
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Using "page" route parameter in convention routing fails with Asp.Net Core Mvc 2.0 #6660
I installed the .NET Core 2.0 Runtime on my server. I restarted my server.
The application builds fine, but when I deploy, it seems my routes -- which worked perfectly in .NET Core 1.1 -- no longer work.
When I try using https://example.com/history (desired URL, which the route SHOULD direct to the "History" action of the "Pages" controller) it complains of a missing View.
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace Framework
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
This is the portion of my /Startup.cs with the routes defined at the end:
PS: There are a bunch of things that can be cleaned up with your code in general but I'll discuss those after we figure out why your views can't be found.
System.InvalidOperationException: The view 'History' was not found. The following locations were searched:
/Views/Shared/History.en-US.cshtml
/Views/Shared/History.en.cshtml
/Views/Shared/History.cshtml
at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable`1 originalLocations)
at Microsoft.AspNetCore.Mvc.ViewResult.d__26.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__17.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__15.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Builder.RouterMiddleware.d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.d__7.MoveNext()
@davidfowl Can that be done through the config? If it requires a rebuild, I will have to wait until later as I am in the office now and the code for this site is at home.
Just to be clear, I'm not saying this is the reason for any failures. It's more about enabling logging by default (and the ability to change it via configuration).
When I switched the DLL references in my project, I suddenly get a Framework.PrecompiledViews.dll file instead of the /Views folder.
Yes, this is one of the new defaults. Any clues if anything here needs to be changed @pranavkm ?
I was looking for the views directory in your application root (not the output). Alternatively if you could share your application that would also work.
if i changed page to pageid the url Community/Page3 display page1
and if i used it as page, now when i navigate between pages they update but i get page1?page=3
note that since it show ?page=3 now my mapping is useless
changed the title [-].NET Core 2.0 route configuration being ignored[/-][+]Using "page" route parameter in convention routing fails with Asp.Net Core Mvc 2.0[/+]on Sep 11, 2017
Hi I have the same issue with routing. The following code worked, but the result looks like this: http://localhost:51409/?page=2, which is not ideal
routes.MapRoute(
name: null,
template: "",
defaults: new { controller = "Product", action = "List" }
);
but when I add {page} variable into Template as following: then the view List is not found.
routes.MapRoute(
name: null,
template: "Page{page:int}",
defaults: new { controller = "Product", action = "List" }
);
@Temoxa, the issue was fixed as part of the 2.0.3 release. Upgrading your package reference - Microsoft.AspNetCore.All to 2.0.3 in CoreCLR projects or Microsoft.AspNetCore.Mvc to 2.0.1 in desktop projects should address this without requiring code changes.
I see a similar issue, but related to using page as a query-string parameter inside of a Razor Pages model. e.g.:
public void OnGet(string page)
Using this, page is set to the path for the current page, which is unexpected. I'm seeing this when using Microsoft.AspNetCore.All 2.0.3 too.
The problem first showed up when using int page, which always comes out as 0 due to the difference in data type when binding.
As suggested, changing this to something like pageNumber is a solution, but that's going to be a pain when using a convention of e.g. int page, int pageSize for pagination.
@Temoxa could you file a new issue that details the issue you're running in to? @serpent5 the term page like the terms controller, action or area is reserved by Mvc for routing and it's attempting to bind the route value. Unfortunately, there isn't a very good solution to this outside of using a different name.
Activity
davidfowl commentedon Aug 15, 2017
Can you show the exception?
PS: There are a bunch of things that can be cleaned up with your code in general but I'll discuss those after we figure out why your views can't be found.
davidfowl commentedon Aug 15, 2017
One more thing, I'd suggest turning up the logging verbosity. That should show you exactly what's happening.
eat-sleep-code commentedon Aug 15, 2017
@davidfowl: Here ya go:
davidfowl commentedon Aug 15, 2017
@eat-sleep-code See my other suggesting about turning up the logging verbosity.
eat-sleep-code commentedon Aug 15, 2017
@davidfowl Can that be done through the config? If it requires a rebuild, I will have to wait until later as I am in the office now and the code for this site is at home.
davidfowl commentedon Aug 15, 2017
@eat-sleep-code It can be done through configuration in 2.0.0 but you didn't update your code to use any of the new APIs.
I'm assuming you also have views in the right folder? Can you show the layout on disk? Are you running behind IIS?
eat-sleep-code commentedon Aug 15, 2017
@davidfowl Do you have an outline of what code changes need to made to use the new APIs?
Yes it is behind IIS. (Windows Server 2016 Datacenter)
When I switched the DLL references in my project, I suddenly get a Framework.PrecompiledViews.dll file instead of the /Views folder.
This route, should (and used to) make it work.
davidfowl commentedon Aug 15, 2017
@eat-sleep-code https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/
Just to be clear, I'm not saying this is the reason for any failures. It's more about enabling logging by default (and the ability to change it via configuration).
Yes, this is one of the new defaults. Any clues if anything here needs to be changed @pranavkm ?
eat-sleep-code commentedon Aug 15, 2017
@davidfowl Thanks for that migration reference. I will have to tackle that stuff tonight.
But you are right, nothing there seems to explain why the silly routes are not working.
pranavkm commentedon Aug 15, 2017
@eat-sleep-code could you include a file list
tree /ffrom your app root?pranavkm commentedon Aug 15, 2017
@eat-sleep-code - sorry, I was specifically looking for the apps Views directory which is missing here.
eat-sleep-code commentedon Aug 15, 2017
@pranavkm Yeah, doesn't get created. Instead I have the Framework.PrecompiledViews.dll.
pranavkm commentedon Aug 15, 2017
I was looking for the views directory in your application root (not the output). Alternatively if you could share your application that would also work.
eat-sleep-code commentedon Aug 15, 2017
@pranavkm I will provide a repo tonight when I get home.
28 remaining items
M-S-M-A-S commentedon Aug 29, 2017
I have the same bug but your solution doesn't fix it
this issue happen because i'm using tag helper
if i changed page to pageid the url Community/Page3 display page1
and if i used it as page, now when i navigate between pages they update but i get page1?page=3
note that since it show ?page=3 now my mapping is useless
[-].NET Core 2.0 route configuration being ignored[/-][+]Using "page" route parameter in convention routing fails with Asp.Net Core Mvc 2.0[/+]Allow "page" route parameter to be used in Mvc controllers
Allow "page" route parameter to be used in Mvc controllers
#2608 Fixed paging. "Page" token became reserved in ASP.NET Core 2. F…
BingZL1983 commentedon Nov 13, 2017
Hi I have the same issue with routing. The following code worked, but the result looks like this: http://localhost:51409/?page=2, which is not ideal
routes.MapRoute(
name: null,
template: "",
defaults: new { controller = "Product", action = "List" }
);
but when I add {page} variable into Template as following: then the view List is not found.
routes.MapRoute(
name: null,
template: "Page{page:int}",
defaults: new { controller = "Product", action = "List" }
);
Can anyone help me out? Thank you!
davidfowl commentedon Nov 13, 2017
Change route name “page” to something else
BingZL1983 commentedon Nov 14, 2017
Hi Davidfowl
Thank you for your response. I have change variable "page" to "pg" as following.
public ViewResult List(string category, int pg = 1)
=> View(new ProductsListViewModel{
Products = repository.Products
.Where(p => category == null || p.Category == category)
.OrderBy(p => p.ProductID)
.Skip((pg - 1) * PageSize)
.Take(PageSize),
PagingInfo = new PagingInfo
{
CurrentPage = pg,
ItemsPerPage = PageSize,
TotalItems = category == null ?
repository.Products.Count() :
repository.Products.Where(e => e.Category == category).Count()
},
CurrentCategory = category
});
routes.MapRoute(
name: null,
template: "{pg}",
defaults: new { controller = "Product", action = "List" }
);
it still didn't work. Do you think it is a bug in ASP Net Core 2.0?
FYI, I started a web app project using empty template. Thank you!
Temoxa commentedon Nov 30, 2017
Hi, I have the same problem BIngZL1983...((
use ASP Net Core 2.0,
but i resolved problem change parametr "page" in routes.... =)
pranavkm commentedon Nov 30, 2017
@Temoxa, the issue was fixed as part of the 2.0.3 release. Upgrading your package reference -
Microsoft.AspNetCore.Allto 2.0.3 in CoreCLR projects orMicrosoft.AspNetCore.Mvcto 2.0.1 in desktop projects should address this without requiring code changes.Temoxa commentedon Nov 30, 2017
Today upgrade to 2.0.3 , but problem saves....(
serpent5 commentedon Dec 16, 2017
I see a similar issue, but related to using
pageas a query-string parameter inside of a Razor Pages model. e.g.:Using this,
pageis set to the path for the current page, which is unexpected. I'm seeing this when usingMicrosoft.AspNetCore.All2.0.3 too.The problem first showed up when using
int page, which always comes out as0due to the difference in data type when binding.As suggested, changing this to something like
pageNumberis a solution, but that's going to be a pain when using a convention of e.g.int page,int pageSizefor pagination.pranavkm commentedon Dec 18, 2017
@Temoxa could you file a new issue that details the issue you're running in to?
@serpent5 the term
pagelike the termscontroller,actionorareais reserved by Mvc for routing and it's attempting to bind the route value. Unfortunately, there isn't a very good solution to this outside of using a different name.Temoxa commentedon Dec 19, 2017
My problem is resolved in version 2.0.3
Allow "page" route parameter to be used in Mvc controllers