Server Error in '/' Application - Runtime Error - Asp.net

Asked

Viewed 2,341 times

3

My application has custom errors working properly.

Only when you add "/...." at the end of the URL (necessarily more than two points), the untreated error "Server Error in '/' Application".

If I add only two points, the application "goes up" one level, as if it changes directory.

I need this to be transparent to the user.

Has anyone ever been through it? Some light?

2 answers

2

This error is appearing because you are encountering some problem in your application. You can change this in Web.Config. It has a tag that calls customErrors, put her as Off.

<configuration>
  <system.web>
    <customErrors mode="Off"/>
  </system.web>
</configuration>

Remembering that you have to do the error handling. My suggestion is you create an error page that redirects the user whenever any unexpected error occurs. For this, you use the tag customErrors and defines a page in the defaultRedirect. You can treat each error with a page. For example a common error is the "HTTP 404 Page Not Found", you can use the statusCode tag error. Another useful parameter is the mode that you define which errors will be displayed to the user. There are 3 values:

  • On: Any error will be redirected to the defined page.
  • RemoteOnly: When you are running the local application, the error appears. When running remotely, you will be redirected.
  • Off: The error will always be displayed.

Some statusCode:

  • 404: Page not found (File not found)
  • 403: Access denied (Access denied)
  • 500: Server error (Server error)

An example of Web.Config:

<configuration>
  <system.web>
    <customErrors mode="On" defaultRedirect="pagErro.aspx">
      <error statusCode="404" redirect="pagNaoEncontrada.aspx" />
    </customErrors>
  </system.web>
</configuration>

Documentation

  • 1

    The site had these redirects that you told me about, but still displayed error when adding points to the end of the URL. The error was not caught even by default redirect. I found the solution, I will put below.

2


Even with the treatments described by @Taisbevalle, the site could not redirect to a default error page when adding any amount of points at the end of the URL.

The solution was to add the tag on the Web.Config:

     <system.web>
       <httpRuntime relaxedUrlToFileSystemMapping="true"/>
        ....
     </system.web>

The path created by /.... was not configured as a valid path. When we assigned true to the parameter relaxedUrlToFileSystemMapping, We allow file names not to have to comply with Windows file standards, so you can release exceptions "404" and be treated by the treatment explained in the response of @Taisbevalle.

Documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.