I am receiving the following error on Android only (fine on iOS)
Shell: Failed to Navigate Back: System.ArgumentException: Ambiguous routes matched for: //D_FAULT_FlyoutItem12/IMPL_homepage/homepage/indexpage/indexpage
I declare the page like so in AppShell
Routing.RegisterRoute("indexpage", typeof(Pages.Index));
Because the content of the page is dynamic, I navigate to it like so
await Shell.Current.GoToAsync($"indexpage?indexid={clicked.ID}");
This works fine when going to an index page from a list
However, when I get to the index page and then go to another page of a different type, also via the route registered in AppShell, but again by passing in an ID, and then try and go back, I get the error
Again, the error only occurs on Android - iOS works fine
or anyone that will face this issue, and have this error message too;
System.ArgumentException: 'Ambiguous routes matched for: ...'
This occures when you register your routes in XAML (in the appshell file) and you also try registering your routes in code behind in C#. Only register your routes once using either XAML or C# not both.
to fix your error: most likely you have a page register 2 times... 1st time register in AppShell.xaml.cs file and 2nd time register in AppShell.xaml.
just remove double register and it should work. good luck
Related
I have a Blazor Server app with a page that takes in parameters in the uri. When I click on an anchor tag that has the route setup to hit that page with params (like below) the link works fine, and the page loads.
<!--link content in here-->
However, if one tries to access the page from that url directly, or manually refreshes in the browser, then the page doesn't reinitialize or hit any breakpoints on the parameters. Instead, it throws a 404 not found.
So two things here:
Firstly, I'm confused about why it works fine from within the anchor tag, but dies any other way. Especially when pages without params in the #page directive work fine with refreshes/direct-urls.
Second, is this an intended behavior for Blazor Server or am I missing something here that's breaking the page refreshes/hitting-url-directly? Doesn't seem like a feature, but maybe I'm misunderstanding Blazor's routing.
Razor and Razor.cs for page in question:
#page "/MyPage/{Param1}/{Param2}"
<h1>MyPage</h1>
<Metrics Param1="#Param1" />
<Details Param1="#Param1" Param2="#Param2" />
<InProgress Param1="#Param1" Param2="#Param2" />
<InQueue Param1="#Param1" />
<br />
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
using MyApp.Data.Models.ApiResponse;
namespace MyApp.Pages
{
public partial class MyPage
{
[Parameter]
public string Param1 { get; set; }
[Parameter]
public string Param2{ get; set; }
public TaskList Tasks { get; set; }
protected override Task OnInitializedAsync()
{
// work in progress, intend to do more here later on
var test = "";
return base.OnInitializedAsync();
}
}
}
Edit(s) -- per comment suggestions
UseEndpoints section of Configure method in Startup.cs:
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
After further digging I noticed that the #param2 will occaionally have a . char in it. Blazor does have a need for configuring routes that have params with dots in them. The below fall back doesn't work:
endpoints.MapFallbackToPage("/MyPage/{Param1}/{Param2}", "/MyPage");
It throws an:
InvalidOperationException: Cannot find the fallback endpoint specified by route values: { page: /MyPage, area: }.
I'm guessing that the area: being empty is a problem but I'm not finding how or where to properly set that. The example from the link shows just the Page's name in the fallback. Could someone please point out what's wrong with this fall back and how one can properly correct it?
My problem was with a dot character being in the parameter's value. When the routing issue is from a "dot" being in the parameter, then doing exactly what the docs recommends does the trick (go figure). You will want to specify a fall back for that particular route like so:
endpoints.MapFallbackToPage("/MyPage/{Param1}/{Param2}", "/_Host");
For WASM projects: you want to specify the html file vs _Host which should be Blazor Server specific.
endpoints.MapFallbackToFile("/MyPage/{Param1}/{Param2}", "index.html");
After this setup is applied, refreshing a page or reaching the URL directly should result in your application working as intended, no more 404 error different from the standard <NotFound> tag setup in the App.razor.
Key points:
Check if your url parameters have any known parsing exceptions like dots (Blazor assumes those are files being requested)
Use the default page of your application for the fall back, not the page you want to hit. In a Server app that's _Host for wasm it's index.html
I have an existing asp.net mvc 4 solution. It has several controllers/models/views in separate folders and all work fine
with both GET and POST controller methods. I have added a new folder and added its own controllers/models/views.
When I call the GET controller method, from the view it works fine. But the POST controller method
throws
HTTP Error 405.0 - Method not allowed. The page you are looking for cannot be displayed because an
invalid method (HHTP verb) is being used.
The following is my view and controller
<div id="usercreds" class="items">
#using (Html.BeginForm("SaveCustomer", "NewCustomer"))
{
//form control code here
}
[HttpPost]
public ActionResult SaveCustomer(NewCustomerModel newCustomer)
{
//more code here
}
I added FormMethod.Post in the Html.BeginForm method and added modules="IsapiModule" in web.config file
I still get the same error.
The issue was there were two identically named folders within the VisualStudio solution. Because of this it was posting to the wrong URL. I renamed one of the folders and it worked fine.
Whenever an error occurs in my application, I'm not able to view the correct error in the event viewer. In it's place I get the following error...
The model item passed into the dictionary is of type 'System.Web.Mvc.HandleErrorInfo', but this dictionary requires a model item of type 'LayoutPageViewModel'
I get why this error occurs (because the controller is trying to pass a model of type HandleErrorInfo to the original view) but what I can't figure out is how stop this error showing up in the event viewer and show the real error.
So the sequence of events are:
Exception occurs in the application
Default error handling tries to pass model of type 'System.Web.Mvc.HandleErrorInfo' into default layout page, which accepts a model of 'LayoutPageViewModel'
Another exception occurs in the application because the layout is being passed a model of type 'HandleErrorInfo'
The custom error 500 page (specified in the web.config) is hit, which doesn't reference any layout:
#{ Layout = null; }
Error page is shown correctly but the exception in the event viewer is incorrect.
I have tried setting the master and view for the HandleErrorAttribute filter in Application_Start but that stops anything being registered in the event logs. I've also tried adding the following method to the controller...
protected override void OnException(ExceptionContext filterContext)
{
filterContext.Result = new ViewResult {
ViewName = "~/Views/Shared/Error.cshtml",
};
}
but that has the same result as the HandleErrorAttribute workaround.
Does anyone have an idea of how I can get around this problem?
Sounds like you are experiencing secondary errors which makes the end result a type based issue.
Would look at the way you display your exception before trying other ways to handle exceptions.
How do you know that the right error page is hit first time?
What content does the error page include, can anything else trigger an error?
Know you said the error page has no ref to layout page. Would double check that this is actually being used and not just being called in second instance, alternately remove layout from main to ensure.
Make sure that your error page always has its own simplified layout page so there is not risk to get a problem due to a strongly typed layout/master page which will result in a similar error to yours.
My solution for dealing with the problem is to remove the #model directive at the top of the layout page and then do some checks where I'd normally expect to see my model to switch between the different models that might get passed in e.g.
#if (Model is System.Web.Mvc.HandleErrorInfo)
{
<title>Error</title>
}
else if (Model.GetType() == typeof(MyApp.Models.LayoutPageViewModel))
{
<meta name="description" content="#Model.PageMetaDescription">
<title>#Model.PageTitleComplete</title>
}
Not sure whats going on, but I have a rewrite with two parameters. For some reason the page is loading twice when it's called. I know that it's the rewrite because it works fine when it's just one parameter. Thanks for any help.
This is in my Global.asax
routeCollection.MapPageRoute("RouteForAlbum", "album/{autoID}/{albumName}", "~/SitePages/AlbumView.aspx");
This is on my page load
if (!Page.IsPostBack)
{
string id = Page.RouteData.Values["autoID"].ToString();
string albuname = Page.RouteData.Values["albumName"].ToString();
}
Wow, found the answer after more searching. If you have javascript reference with ../ this causes issues with URL rewritting.
asp.net Multiple Page_Load events for a user control when using URL Routing
UDPATE:
This can also happen when using CSS3PIE together with ASP.net Routing and the two don't play nicely together.
Any CSS3PIE css styles with a URL in the value can cause the target page to execute the code behind multilple times. For me specifically, it was these two lines:
behavior: url(PIE.htc);
-pie-background: url(bg-image.png) no-repeat, linear-gradient(#FFFFFF, #53A9FF);
Changing the above two lines to start with a leading slash "/" fixed it along with specifying the whole path to the files.
behavior: url(/scripts/PIE-1.0.0/PIE.htc);
-pie-background: url(/scripts/PIE-1.0.0/bg-image.png) no-repeat, linear-gradient(#FFFFFF, #53A9FF);
I am building a custom module for DNN 05.04.02.
I want to add a custom action to the module for downloading submitted files. I am able to get the link to appear but the url parameter is a mystery. I have tried dozens of combinations and it either leads me to page not found or a blank page with no errors that is incorrect. The page I want to reach is called Download.ascx and all of the work i have done is based off the Visual Studio DNN Module Template. What am i missing with the url parameter?
From: ViewDataValidation.ascx
public ModuleActionCollection ModuleActions
{
get
{
ModuleActionCollection Actions = new ModuleActionCollection();
Actions.Add(GetNextActionID(),
"Download Validated Files",
"Download",
"",
"edit.gif",
EditUrl("Download"),
false,
DotNetNuke.Security.SecurityAccessLevel.Admin,
true, false);
return Actions;
}
}
Take a look at Joe Brinkman's blog post exploring all of the functionality of the actions. It looks like the URL property is expecting an absolute URL (i.e. something starting with http://).
There's also the option to fire a server-side event, which you can then use to do the redirect manually, if that would be easier.
If you're navigating to an internal page, you might also try passing in the result from calling Globals.NavigateURL(tabId).