Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a website with a number of aspx pages.

And one of the pages is designed to display the fetched data from previous page.

So when an user tries to access this particular webpage by typing url then it obviously shows error with codes.

I do not want to show any code errors to users but the error page such as "Error 404: Not Found or Page can't be displayed" error pages.

As this particular page gets data entered from previous page, there must be an error when accessing from typing url with no data input.

So please help me figuring out this for me.

I am using Visual Studio 2015 with VB.Net



Thanks
Posted
Comments
Mathi Mani 11-Nov-15 19:26pm    
Since this page requires data from a previous page, check if the data is populated in page load method of the page you do not want to be directly accessed by URL. If it is not, throw an exception and show page based on that.
[no name] 11-Nov-15 23:38pm    
You can implement own inside your page. Let's take an example: Suppose there two web pages Form1.aspx and Form2.aspx. Then user need to enter in Form1 page and data will display in Form2 page. But a user tried to access directly Form2 page and here you need to display error message "Input is required.". You can implement logic inside page_Load() of Form2 page and validate data. if data is not there then display error message.
I have one doubt here is when a user access Form2 page directly why are getting "Page not found" error. I think you implemented some other logic.

Using a 404 in this situation would break http standards. As suggested in the comments simply code for the situation where the page is accessed directly.

Have an error message in an asp:Literal on the page with Visible=false then in your code behind;

If Not dataFound Then
    LiteralMyError.Visible = True
    Exit ' not sure if this is how you abort a function, I dont know vb.net
End If
 
Share this answer
 
VB
Function Create() As ActionResult
       Try
           ' TODO: Add insert logic here
           Return RedirectToAction("Index")
       Catch
           Return View('Error')
           ' or redirect to your custom error page
       End Try
   End Function


If you are not using MVC, just write technology you use and I will edit my answer ;)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900