Re: 404 best practice

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks, Bruce. Unfortunately, the 404 page derives from a master
page, which checks session. After some research, it seems the
Application_Error no longer holds a reference to the current
HttpContext, so redirecting from that causes the 404 page to create
that obscure error about not having session enabled.

D

On 31 May, 16:00, bruce barker <nos...@xxxxxxxxxx> wrote:
a redirect is a 302. you should do a server transfer rather than a
client redirect.

-- bruce (sqlwork.com)



Dunc wrote:
I have a website where I wish to display a custom 404 error page when
applicable. I also want to ensure that when a search engine hits a
page that no longer exists, it gets a StatusCode of 404 so it will
eventually remove it from it's index.

Currently to do this, I'm capturing all errors using the
global.asax.cs -> Application_Error proc, setting the approriate
status code and redirecting:

if (CheckForErrorType(exc, "System.Web.HttpException") &&
exc.Message.ToString().IndexOf("does not exist") > 0)
{
Response.StatusCode = 404;
Response.Redirect("/pagenotfound.aspx", true);
}

When I load Fidder, it tells me that the missing page *is* being
loaded, returning a status code of 302 (object moved) then my friendly
error page is being loaded with the appropriate 404 code which is
useless.

My 404 page inherits from a Master Page, which checks for a Session so
I can't use a Server.Transfer as I get the error:

An exception of type 'System.Web.HttpException' occurred in
System.Web.dll but was not handled in user code

Additional information: Session state can only be used when
enableSessionState is set to true, either in a configuration file or
in the Page directive. Please also make sure that
System.Web.SessionStateModule or a custom session state module is
included in the <configuration>\<system.web>\<httpModules> section in
the application configuration.

Alternatively, I've tried using the CustomErrors tag in web.config:
<customErrors mode="RemoteOnly">
<error statusCode="404" redirect="/pagenotfound.aspx"/>
</customErrors>

Again, using Fiddler, it returns first the 302 status then the 404.

Has anyone else come across this issue and found a decent solution?

TIA- Hide quoted text -

- Show quoted text -


.



Relevant Pages

  • Re: Saturday at the library/Bruce Brunch
    ... Eric Meola and Daniel Wolff each gave a ... session. ... "The Other Band," Dave's all time fave Bruce show, why ... Eric Meola discusses the photo shoot for Born To Run that has turned ...
    (rec.music.artists.springsteen)
  • Re: FreeBSD Security Advisory FreeBSD-SA-03:12.openssh
    ... by generating a different key for each session you get better ... > entropy, which makes for better encryption, especially when you ... > run sshd out of inetd. ... I wonder what Bruce Schneier would think of Mr. Simpson's ...
    (FreeBSD-Security)
  • Re: FreeBSD Security Advisory FreeBSD-SA-03:12.openssh
    ... > When you run out of inetd to service a single connection, ... by generating a different key for each session you get better ... run sshd out of inetd. ... I wonder what Bruce Schneier would think of Mr. Simpson's ...
    (FreeBSD-Security)
  • Re: Different same machine browser sessions intefering with each other with Forms Authentication and
    ... Hi Bruce. ... by "you are probably storing session is a vb module". ... First of all, we are using forms authentication, e.g. calls to ... some other application session state that we store in the Session built ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Quick question about expect
    ... Bruce, ... creates a screen session inside your intitial session. ... to be able to connect to have multiple sessions (whatever they may be, ssh, ... have you initial script/alias do ...
    (comp.lang.tcl)