no idea where to start on this one, but here goes. if i've missed an answer somewhere is becuase i don't know how to search for the error.
take a aspx page i.e. www.example.com/about when testing i have found (accidently i must say) that adding /anything i.e. www.example.com/about/eduhdbbw still returns the www.example.com/about page (assuming www.example.com/about/eduhdbbw doesn't exist). i would expect a 404 in this situation but i don't really know how it is routing to the original page.
fyi i'm using VS 2017 community with iis and asp.net webforms with c# and the error occurs in vs and compiled in iis. if any other info is needed please ask.
Edit: the about page does indeed show .aspx in the browser url. Also i am using a blank webform template, so it didn't come with anything pre-installed and i've not written and url re-write.
Pathinfo sound like it might be something but would this affect a project with just basic aspx and code behind, amd basically no other dependancy?
Also for now i am just using absolutepath to compare the page name and sending to 404 if it doesn't math; but it seems like a sloppy solution to have on every page...
I'm working with webbrowser tool trying to build my own browser.
Something that i'm having trouble doing is the history part.
When the document completes navigating , I search in my database if its URL doesn't exist then I add it to the history, else I just increase the "counter" of this page in the database.
The problem is that when I enter some pages each time it gives me different URL but it's the same page ! such as google.com , when I navigate to it it gives me in the first time (for example) : https://www.google.co.il/?gws_rd=cr&ei=eBP-UtPCOMi84ASukoCAAw
the second time I navigate :
https://www.google.co.il/?gws_rd=cr&ei=rhP-UpW6CYG54ATAqIHIDg
Is there a way to identify that both these URLs lead to the same page ??
I'm trying to do this because when I load the history to my application , many URLs are loaded that are leading to the same page.
Any help is appreciated , thanx in advance
You can use the Uri object and ask for the AbsolutePath property
I personally would expect my browser to have the history by URL and not by content (that's what you actually try to do as far as I understand). But if you want to avoid these multiple entries, you might calculate a hash code for each content received by that page and increase your counter.
The problem is that you cannot know what the server will do with that URL. It might be the same today and different tomorrow. I also wouldn't just go for the URL without the parameters because on other pages the parameter might make a really important difference.
Another note: In case you hash the content, you might want to exclude things like 404 pages (which can occur with different URLs and shouldn't be grouped under the same hash.)
Right now i have a folder with another folder inside of it. The two folder names are called "pc details" and "pchardwaredetails"
When on a page in "pchardwaredetails" i want to return to a page in "pc details" using a button and response.redirect() but the file paths are just getting too complicated for me. What might the file path be from a page called "Details" in "pchardwaredetails" to a page called "viewMore" in "pc details"?
Also please feel free to explain how paths work so i know for future
thanks
Usually the Referrer of the page (a HTTP header), tells you what page you've come from so to go back you should just be able to do:
Response.Redirect(Request.UrlReferrer.ToString());
That's assuming you came from PC Details. However if you land on PC Hardware Details from some other page then that won't work, you would have to hard code the back feature.
You can simplify ASP.NET paths and use ~, for example:
Response.Redirect("~/some/path/pc_details.aspx");
i am facing one issue in my asp.net 3.5 application.
www.abc.com/default.aspx - this works perfectly
when user tries to add anything after aspx after / like www.abc.com/default.aspx/xyz
my css gets disabled, and page works which i dont want.
i have used error pages but it didnt work in this . i want to disable anything user enters after url www.abc.com/default.aspx
if user enters www.abc.com/default.aspx/xyz it should display error page
how to do it ?
thankx in advance
This belongs to StackOverflow.
but this sounds like is a simple issue that your CSS is relative (does not start with /), try change the <link> in the <head>-section to have a forward slash at first.
I have found huge amounts of information (ie, this) on how to handle unexpected errors in ASP.NET, using the Page_Error and Application_Error methods as well as the customErrors directive in Web.config.
However, my question is what is the best way to handle EXPECTED errors. For example, I have a page to display a record. Each record has a specific list of users who are allowed to see it. Since many users may have the "View Records" role that are not on said list, I have to write some code on the page to filter them.
protected void Page_Load(object sender, EventArgs e)
{
var user = Membership.GetUser();
if (!CanUserViewThisRecord(Request["id"], user.Username)
{
// Display an error to the user that says,
// "You are not allowed to view this message", and quit.
}
else
{
// Display the page.
}
}
What are the best practices for handling this kind of error? I can think of a few possibilities:
Redirect to an error page.
Put a label on every page called "lblErrorText". Leave it blank unless there is an error.
Raise an exception and let the standard error handling deal with it.
This feels like a basic question and for that I apologize, but just about everything I've found has been in reference to unexpected exceptions. It's not that any of the above possibilities are hard to implement, but I'd like to use a standard, recommended method if possible.
NOTE: Thanks everyone for the answers. I want to clarify that users would NOT have the ability to click links to records they're allowed allowed to view. This question is more in the interest of being defensive. For example, since the record ID is in the URL someone could potentially enter the ID of a forbidden record in the address bar. Or User A who is allowed might e-mail a link to User B who is not. It seems I may not be using the words "exception" and "error" in the correct way, but hopefully the scenario makes sense.
In the interest of failing gracefully, I'd go with the option to display a message on the page.
Even better is error prevention; if you know ahead of time that the user won't be able to do anything on the page, don't provide a link to it. Generally, users should only see the things that they are allowed to do.
As others have mentioned, I would prefer to prevent this before it gets sent, either by disabling the functionality for these users, or catching it with javascript before the page is sent.
you would still need to check on the server that the user is allowed to make use of a control, and in such cases the suggested label would be preferable as a solution to the other 3 given.
A further solution however would be to provide a hidden value to the page which is checked by javascript within the page, generating either an alert or a more easily spotted error dialogue than a label somewhere which might be missed leading to confusion as to why nothing happened.
Edit based on questioner's comments: if modifying a number in a URL is all that is required to point to records the user is unauthorized to use, would POST perhaps be a better method to use than GET? that way the way this error is handled is less important, as no standard user would encounter it.
Of your three options, the third would be my least favored. It's not really an exception for a user to try to view a record you told him was there. Redirecting to an error page is more reasonable, as is the error label. However, neither is particularly user-friendly.
I don't know how your UI is structured, but it seems to me that you shouldn't let the user try to view a record if you know that the user isn't allowed to view it. That is, if you know that the user can't view that record, then don't give him the opportunity to click on it. Never get to the point where you have to say, "You can't view this record."
If you can't prevent the user from trying to view the record, I think a pop-up message box would be preferable to either of your first two options.
in my opinion this question is more methodology then tech..
i think is more right to show the error message near the object/action that cause the error.
if you send him to another page he will lost is orientation and it not be clear what cause this error.
so in my opinion is more right to put the error message in the same page.
and maybe give him the opportunity to correct..