Is it possible to get routedebbuger result when user hits 404? - asp.net

May be I'm missing something, but the way now routedebbuger works (2+ version) is that it renders it's results on end of the page, which may be useful sometimes, but more often is annoying.
Would it be possible to return routedebbuger results only in case, when page is not found, when probability that our routing does not work as it supposed to work is the highest? In such case I would get information what is wrong right away, when I need it most (sure, this behavour would be enabled only in debug mode) .
If so, how to do that?

If you have a custom error controller and 404 view, you can use the version of Phil Haack's route debugger code that I put together to serve as a control on each page, which will be served even if you hit a 404.

Related

how to avoid HTTP status code 404 on nuxt error.vue

Using Nuxt, we need to be able to render pseudo-routes, like this:
https://server.com/non-existent-route
Where "non-existent-route" is a dynamic path.
Normally, this would render error.vue. This is fine, as we've subverting the use of this page to render what we want. But... we just discovered that Nuxt is sending a 404 anyway! This only happens when the page is first loaded in a fresh tab, for some reason. This is very bad.
So, we need a way to avoid HTTP status 404 in some cases.
We found this:
https://medium.com/finn-no/hacking-nuxts-404-logic-for-maximum-awesome-and-easy-proxying-e4efaeb03d66
which is actually not as helpful as we had hoped it would be, as it simply provides a way to proxy another URL, sending us back to the same problem.
We suspect there might be some middleware solution to this problem... but have not been able to come up with it.
Turns out the answer was right here all long:
https://nuxtjs.org/guide/routing#dynamic-nested-routes
Rather disappointing that nobody suggested this extremely simple solution.

why Webapp2 redirect to a page but it's not reload?

I am using a webapp2 in GAE, when I called self.redirect to some page like below:
self.redirect(some_url)
which returned a page looks like cached, I have to refresh/reload the page so that I would get latest data.
Is there any cache setting for webapp2? or I have to set some properties for response of that page? Please advise.
In my project I've fixed that by adding time.sleep(0.1) just before the self.redirect('someurl') call.
Not sure if it is a best way to solve the problem, but pages started to show most recent info.
Edit: beware of consistency issue
Check out #Lindsay answer. Using time.sleep(0.1) might give you the expected result in a local environment, but you cannot trust it in a production environment. If you really need results to be strongly consistent, use an ancestor query, not time.sleep(0.1).
My guess is that this is happening because the earlier page is updating an entity that is then being accessed on the later page by means of a non-ancestor query. A non-ancestor query provides eventual-consistency rather than strong-consistency, so the problem is not that the page isn't being refreshed, but that it's showing what the data looked like before the update was completed. When you refresh, or add a call to time.sleep(), you may be providing enough time for the datastore to catch up, especially during testing. However, in production, your sleep may not be long enough in all cases, and the same is true of a page-refresh.
If you check your application and find out that you are using a non-ancestor query, and therefore your problem is indeed eventual-consistency vs strong-consistency, a Google search will show you that many pages discuss that topic; here's one: https://cloud.google.com/developers/articles/balancing-strong-and-eventual-consistency-with-google-cloud-datastore#ftnt_ref1.
The simplest solution seems to be to create an entity group and use an ancestor query, though that comes with a possible performance hit and a limitation of one update per second per entity group.
Got the same problem I have done a trick which is not good but helped me anyway. Called a temporary view file then did html redirect:
<meta http-equiv="refresh" content="0.5;URL='/'">
Hope it helps. any one with a better answer?
Do you call return immediately after the self.redirect(some_url)? It may be falling through to other code that renders a page.

Erratic requests arising from client when using a custom view engine in ASP.Net MVC

I have spent about 7 hours trying to figure this out but gotten nowhere.
This is how my fiddler trace looks like
I have two routes that look like below that are registered for this page.
[route name="DummyResultsWithMarketStateNames" url="DummyResults/state-{statename}/market-{marketname}/page-{page}/{action}"
controller="DummyResults" action="Show"/]
[route name="DummyResultsWithMarketId" url="DummyResults/market-{marketid}/page-{page}/{action}"
controller="DummyResults" action="Show"/]
For this url, the first route matches and it goes to the right action. However, the client is sending in another request a second later in which it removes the last parameter 'page-1' and replaces it with 'none'. I've traced for XHR's and there are none. I'm not sure if this is an issue with the MVC framework itself but how would that translate as a request from the client?!!! Also, I'm getting different behavior with different browsers (IE trace above). Anyone encountered such strange behavior? I'd be happy to provide more info if you'd like.
UPDATE:
I setup the site on IIS and eliminated all image, css or script requests. I still end up with multiple requests. The original dummyresults page seems to be working now after I removed the .htc's. However, I have another page (screenshot below) that is not 'co-operating'. Should I add Ignoreroutes for certain extensions? This is driving me nuts!!! Pardon the 'bleep' on the image (IP reasons). PS: I setup another site for serving up all static resources.
Q: Should I add Ignoreroutes for certain extensions?
A: Of course! By default the WCF extension "*.svc" is ignored. The first thing I add on a ne page is for instance the ignore rule for the favicon.ico.
RouteTable.Routes.IgnoreRoute("*.svc");
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.IgnoreRoute("favicon.ico");

ASP.NET renders incomplete HTML

I have an asp.net C# .net 3.5 page which contains several user controls. I am noticing that sometimes the html loaded on the browser is incomplete. It seems to get cut-off.
Any suggestions on how to troubleshoot whats the root cause?
This can be symptomatic of server errors or proxy problems. I would use Fiddler to check what's going back and forth between your browser and the server. If you are getting any 500 (server error) response codes, that would be a good place to look.
Another thing to check would be javascript errors on the page, because depending on what your javascripts are doing, errors can prevent loading of other content in some cases.
womp probably has most of the bases covered, but the other angle that can lead to issues like this would be exceptions getting eaten but causing processing to stop, thereby sending half the page or somesuch.
Verify that your HTML is being written to the page by viewing the source code of the page after it loads. My guess is that the HTML that is being output is invalid, and that the browser isn't able to properly display it. Make sure all your HTML tags are properly closed and balanced.
It could also be an issue with the request being ended midway through. Try removing one control at a time from the page and see if the situation improves. If it does, you'll know which control is to blame.
It is quite unlikely that it is the same problem, but I had that happen before where the page had a custom filter attached to response.filter which reformatted the output to fix up some dotnet SEO problems. And the one we wrote had a bug where one regular expression consumed a bit too much copy in some instances and broke the output

Give user a 404 if querystring is missing?

Say that I require a querystring; for example "itemid". If that querystring is for some reason missing, should I give the user a 200 error page or a "404 Not Found"?
I would favour 404 but I'm not really sure.
Maybe you should give a "400 Bad Request".
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html for more possibilities.
And like Chris Simpson said give a "404 Not Found" when no item for the corresponding item id is found.
You could also check popular RESTful apis to see how others have handled the problem. For example Twitter.
Good question. Personally I would use a 200 and provide a user friendly error explaining the problem but it really depends on the circumstances.
Would you also show the 404 if they did provide the itemid but the particular item did not exist?
From a usability standpoint, I'd say neither.
You should display a page that tells the user what's wrong and gives them an opportunity to fix it.
If the link is coming from another page on your site (or another site), then a page that tells them that the requested item wasn't found and redirects them to an appropriate page, maybe one that lets them browse items?
If the user's typing the querystring themselves, then I'd have to ask why? Since the URI isn't typically user-friendly.
You should give a user 200, only when the HTTP Request you got was responded with an appropriate Response, even when it is only a simple HTML that says they are missing a parameter.
The 404 code is when the User Agent is requesting a resource that is missing.
Check this list for further info
http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
Give a 500 error, probably a 501. This will allow a browser or code to handle it through existing onError mechanisms, instead of having to listen for it in some custom way.
The way I see this working, you should return a 200 - because it should be a valid resource.
Let's say one of your URLs is widgets.com/browse.php?itemid=100 - and that URL displays a specific item in your catalog.
Now, a user enters widgets.com/browse.php - what do we expect the action to be? To list all of the items in your catalog, of course (or at least a paginated list).
Rethink your URL structure and how directory levels and parameters relate to one another.

Resources