0

Whenever error rises in my application, the server redirects it to the error pages, but the url of that page is visible which could be directly accessible.

for example, if error of 404 rise, it gives the url

http://www.example.com/ErrorPages/Error.aspx
http://www.example.com/ErrorPages/500.aspx

I want to hide that page link. In Web.config I am doing

<customErrors mode="RemoteOnly" defaultRedirect="~/ErrorsPages/Ooops.aspx">
    <error statusCode="404" redirect="~/ErrorsPages/ErrorPage.aspx"/>
    <error statusCode="401" redirect="~/ErrorsPages/401.aspx"/>
    <error statusCode="500" redirect="~/ErrorsPages/500.aspx"/>
</customErrors>

Does anybody have a suggestion for this?

Hassaan
  • 3,661
  • 10
  • 28
  • 61
  • you want that users can not access to ErrorPage.aspx directly? – Hamed Khatami Jun 18 '14 at 07:39
  • If you hide the page url, it is still accessible by everyone. – Marco Jun 18 '14 at 07:39
  • 2
    http://stackoverflow.com/questions/16054809/display-custom-asp-net-error-page-without-rewriting-url – x2. Jun 18 '14 at 07:39
  • @hamedkhatami ye i wnt user not to access that page directly just by typing the path – Hassaan Jun 18 '14 at 07:40
  • 1
    possible duplicate of [ASP.NET custom error page - Server.GetLastError() is null](http://stackoverflow.com/questions/343014/asp-net-custom-error-page-server-getlasterror-is-null) – Ole Viaud-Murat Jun 18 '14 at 07:40
  • Why do you not want users to access that page through the URL? Does your error page display information it should not when it doesn't have an error? – Nzall Jun 18 '14 at 07:45
  • @HassaanKhan My comment is not completely correct, it is not exactly a duplicate,but the answer to the question i linked shows how to do a ResponseRewrite so that the visible URL doesnt change when opening the Error page without losing the Error Information. – Ole Viaud-Murat Jun 18 '14 at 07:54

1 Answers1

0

Use following code in Form_Load

Exception exception = Server.GetLastError();

            if (exception == null)
            {
                //redirect
            }

When exception not occur,you can redirect user to not found page

it's easy approach to restrict user to access error page directly.

Hamed Khatami
  • 515
  • 1
  • 5
  • 14