473,385 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Catching 404 errors at Application Level

JJ
I only want to catch 404 errors at the application level (the rest are will
be handled by the customerrors section of the web.config). How do I check
for the error code in the
Application_Error of Global.asax ?

Thanks,
JJ
May 26 '07 #1
25 2338


--
Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message news:eF**************@TK2MSFTNGP02.phx.gbl...
>I only want to catch 404 errors at the application level (the rest are will be handled by the
customerrors section of the web.config). How do I check for the error code in the
Application_Error of Global.asax ?

Thanks,
JJ

May 26 '07 #2
Sorry about the previous blank reply...

re:
!How do I check for the error code in the Application_Error of Global.asax ?

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

Then, in Errors.aspx :
---------------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException, HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" & appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
<hr>
<p>Return to <a href="/">Your application's entry page</a>
</body>
</html>
-------------

You don't need to catch all those errors if you don't want to, but why only
catch 404 errors when all the ones listed in the Case statement are available ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message news:eF**************@TK2MSFTNGP02.phx.gbl...
>I only want to catch 404 errors at the application level (the rest are will be handled by the
customerrors section of the web.config). How do I check for the error code in the
Application_Error of Global.asax ?

Thanks,
JJ


May 26 '07 #3
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Sorry about the previous blank reply...

re:
!How do I check for the error code in the Application_Error of
Global.asax ?

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

Then, in Errors.aspx :
---------------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException,
HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" &
appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the
inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true"
runat=server/>
<hr>
<p>Return to <a href="/">Your application's entry page</a>
</body>
</html>
-------------

You don't need to catch all those errors if you don't want to, but why
only
catch 404 errors when all the ones listed in the Case statement are
available ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>I only want to catch 404 errors at the application level (the rest are
will be handled by the
customerrors section of the web.config). How do I check for the error
code in the
Application_Error of Global.asax ?

Thanks,
JJ




--
http://www.markrae.net

May 26 '07 #4
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Case 404
errMessage &= "The page you have requested can't be found."
Doesn't this only work for pages which are processed by ASP.NET e.g. *.aspx
etc...?

Would this still work for something like:
http://www.mydomain.com/thispagedoesntexist.htm
--
http://www.markrae.net

May 26 '07 #5
re:
!Would this still work for something like:
!http://www.mydomain.com/thispagedoesntexist.htm

No, it wouldn't...unless you add *.htm/*.html to the aspnet_isapi.dll file mappings.

Most asp.net developers don't run .htm/.html files, though.
If they do, adding them will take care of the problem.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:OZ**************@TK2MSFTNGP05.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
> Case 404
errMessage &= "The page you have requested can't be found."

Doesn't this only work for pages which are processed by ASP.NET e.g. *.aspx etc...?
Would this still work for something like: http://www.mydomain.com/thispagedoesntexist.htm

May 26 '07 #6
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:OJ**************@TK2MSFTNGP05.phx.gbl...
re:
!Would this still work for something like:
!http://www.mydomain.com/thispagedoesntexist.htm

No, it wouldn't...unless you add *.htm/*.html to the aspnet_isapi.dll file
mappings.
That's what I thought...
Most asp.net developers don't run .htm/.html files, though.
If they do, adding them will take care of the problem.
Indeed - was just checking... :-)
--
http://www.markrae.net

May 26 '07 #7
re:
!Indeed - was just checking... :-)

Much appreciated, as I had not made that clear.

One more thing I should add is that the sample code will *only* catch HttpException errors.

Coding exception catching should still be programmed into the page,
using Try, Catch, Finally syntax.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:u8**************@TK2MSFTNGP02.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:OJ**************@TK2MSFTNGP05.phx.gbl...
>re:
!Would this still work for something like:
!http://www.mydomain.com/thispagedoesntexist.htm

No, it wouldn't...unless you add *.htm/*.html to the aspnet_isapi.dll file mappings.

That's what I thought...
>Most asp.net developers don't run .htm/.html files, though.
If they do, adding them will take care of the problem.

Indeed - was just checking... :-)
--
http://www.markrae.net

May 26 '07 #8
JJ
Thanks for that. Unfortunately, it has exposed another problem:

The solution works well for when a user tries to access an aspx page that
does not exist, but when I type a partial directory name in the url like:

http://www.mysite.com/testdirecto

The error page gets displayed, but with no theme and loss of all the
graphics (like the page has lost its reference to the themes folder).
When debugging the Global.asax line 'Server.Transfer("~/Error.aspx")' is run
several times when entring a url like the one above, yet on typing a full
reference to a non existent aspx page the line only gets run once and the
error page displays correctly..

Any ideas what the problem is here?

Many thanks,

JJ
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Sorry about the previous blank reply...

re:
!How do I check for the error code in the Application_Error of
Global.asax ?

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

Then, in Errors.aspx :
---------------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException,
HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" &
appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the
inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true"
runat=server/>
<hr>
<p>Return to <a href="/">Your application's entry page</a>
</body>
</html>
-------------

You don't need to catch all those errors if you don't want to, but why
only
catch 404 errors when all the ones listed in the Case statement are
available ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>I only want to catch 404 errors at the application level (the rest are
will be handled by the
customerrors section of the web.config). How do I check for the error
code in the
Application_Error of Global.asax ?

Thanks,
JJ



May 26 '07 #9
JJ
I see that, as pointed out by Mark that Server.Transfer doesn't work for non
aspx pages.
This problem raises its head when you try entering a non exisitent url
without the '.aspx'.

I would guess that at the 'Global.asax' level I need to check if the
referring url has a '.aspx' extension on it and if it doesn't, use
Response.Redirect instead.
I'm currently trying to work out how I do that....

I'm beginning to confuse myself as to why using the customErrors section of
the web.config is not enough in itself. I guess this doesn't kick in when an
unhandled expception is encountered...

JJ
"JJ" <ab*@xyz.comwrote in message
news:Oa**************@TK2MSFTNGP05.phx.gbl...
Thanks for that. Unfortunately, it has exposed another problem:

The solution works well for when a user tries to access an aspx page that
does not exist, but when I type a partial directory name in the url like:

http://www.mysite.com/testdirecto

The error page gets displayed, but with no theme and loss of all the
graphics (like the page has lost its reference to the themes folder).
When debugging the Global.asax line 'Server.Transfer("~/Error.aspx")' is
run several times when entring a url like the one above, yet on typing a
full reference to a non existent aspx page the line only gets run once and
the error page displays correctly..

Any ideas what the problem is here?

Many thanks,

JJ
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Sorry about the previous blank reply...

re:
!How do I check for the error code in the Application_Error of
Global.asax ?

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

Then, in Errors.aspx :
---------------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException,
HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" &
appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the
inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true"
runat=server/>
<hr>
<p>Return to <a href="/">Your application's entry page</a>
</body>
</html>
-------------

You don't need to catch all those errors if you don't want to, but why
only
catch 404 errors when all the ones listed in the Case statement are
available ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
>>>I only want to catch 404 errors at the application level (the rest are
will be handled by the
customerrors section of the web.config). How do I check for the error
code in the
Application_Error of Global.asax ?

Thanks,
JJ




May 26 '07 #10
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:OB**************@TK2MSFTNGP06.phx.gbl...
One more thing I should add is that the sample code will *only* catch
HttpException errors.

Coding exception catching should still be programmed into the page,
using Try, Catch, Finally syntax.
Absolutely!
--
http://www.markrae.net

May 26 '07 #11
JJ
This is the way I have done it, at least until you more experienced
programmers can tell me how it shoud be done:

In Global.asax I have put:
protected void Application_Error(Object sender, EventArgs e)
{
Exception ex = Server.GetLastError().GetBaseException();
if (ex is HttpException )
{
if (this.Request.Url.ToString().EndsWith(".aspx"))
{
Server.Transfer("~/Error.aspx");
}

}
In order to deal with all the possible urls that are not ending in '.aspx' I
have left the customError section in web.config to 'On', and set it to point
to the same Error.aspx page as in the Global.aspx file.

In the Error.aspx page I check for an exception (as would be received if the
last statement was the 'Server.Transfer("~/Error.aspx")' line in
Global.asax, and if the exception is not null, I proceed with the code
detailed by Juan.

If the Exception is not present, I know we have reached the page by way of
the customErrors section (redirect I guess), and based on the
queryparameter, I can display the appropriate error message.

This is the only way I could get application level exceptions handled AND
cope with weird/non aspx/non existent page requests.

Now someone will tell me there's a much easier way.... ;-)

JJ

"JJ" <ab*@xyz.comwrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
>I see that, as pointed out by Mark that Server.Transfer doesn't work for
non aspx pages.
This problem raises its head when you try entering a non exisitent url
without the '.aspx'.

I would guess that at the 'Global.asax' level I need to check if the
referring url has a '.aspx' extension on it and if it doesn't, use
Response.Redirect instead.
I'm currently trying to work out how I do that....

I'm beginning to confuse myself as to why using the customErrors section
of the web.config is not enough in itself. I guess this doesn't kick in
when an unhandled expception is encountered...

JJ
"JJ" <ab*@xyz.comwrote in message
news:Oa**************@TK2MSFTNGP05.phx.gbl...
>Thanks for that. Unfortunately, it has exposed another problem:

The solution works well for when a user tries to access an aspx page that
does not exist, but when I type a partial directory name in the url like:

http://www.mysite.com/testdirecto

The error page gets displayed, but with no theme and loss of all the
graphics (like the page has lost its reference to the themes folder).
When debugging the Global.asax line 'Server.Transfer("~/Error.aspx")' is
run several times when entring a url like the one above, yet on typing a
full reference to a non existent aspx page the line only gets run once
and the error page displays correctly..

Any ideas what the problem is here?

Many thanks,

JJ
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Sorry about the previous blank reply...

re:
!How do I check for the error code in the Application_Error of
Global.asax ?

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("Errors.aspx")
End Sub

Then, in Errors.aspx :
---------------------------------
<html>
<script language="VB" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim errMessage As String = ""
Dim appException As System.Exception = Server.GetLastError()
If (TypeOf (appException) Is HttpException) Then
Dim checkException As HttpException = CType(appException,
HttpException)
Select Case checkException.GetHttpCode
Case 400
errMessage &= "Bad request. The file size is too large."
Case 401
errMessage &= "You are not authorized to view this page."
Case 403
errMessage &= "You are not allowed to view that page."
Case 404
errMessage &= "The page you have requested can't be found."
Case 408
errMessage &= "The request has timed out."
Case 500
errMessage &= "The server can't fulfill your request."
Case Else
errMessage &= "The server has experienced an error."
End Select
Else
errMessage &= "The following error occurred<BR>" &
appException.ToString
End If
ErrorMessage.Text = errMessage & "<BR>We're sorry for the
inconvenience."
Server.ClearError()
End Sub
</script>

<body>
<hr>
<asp:label id="ErrorMessage" font-size="12" font-bold="true"
runat=server/>
<hr>
<p>Return to <a href="/">Your application's entry page</a>
</body>
</html>
-------------

You don't need to catch all those errors if you don't want to, but why
only
catch 404 errors when all the ones listed in the Case statement are
available ?


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message
news:eF**************@TK2MSFTNGP02.phx.gbl...
I only want to catch 404 errors at the application level (the rest are
will be handled by the
customerrors section of the web.config). How do I check for the error
code in the
Application_Error of Global.asax ?

Thanks,
JJ




May 26 '07 #12
"JJ" <ab*@xyz.comwrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
>I see that, as pointed out by Mark that Server.Transfer doesn't work for
non aspx pages.
It's not that Server.Transfer doesn't work for non aspx pages per se, but
rather that non aspx pages (e.g. *.htm etc) don't actually get processed by
ASP.NET's ISAPI DLL by default. This can be changed, but that requires
access to IIS on the webserver itself...
This problem raises its head when you try entering a non exisitent url
without the '.aspx'.
Same problem...
I would guess that at the 'Global.asax' level I need to check if the
referring url has a '.aspx' extension on it and if it doesn't, use
Response.Redirect instead.
See above - only files which are "recognised" by the ASP.NET ISAPI will
actually get processed by ASP.NET... If you try to access a missing HTML
file, ASP.NET won't even figure in the equation, so the contents of
Global.asax et al is completely irrelevant...
I'm currently trying to work out how I do that....
I don't think you can, unless you can add the file extension(s) in question
to the ASP.NET ISAPI filter...
I'm beginning to confuse myself as to why using the customErrors section
of the web.config is not enough in itself. I guess this doesn't kick in
when an unhandled expception is encountered...
See above.
--
http://www.markrae.net

May 26 '07 #13
JJ
Hi Mark.

As this will likely be on a shared web server, I won't have access to IIS.

I think I understand, but it seems the method I've used does bypass the
problem (fingers firmly crossed).

The site in question doesn't have any html files, but I do want it to handle
'user' errors, like typing in a non existent url (with or without any
extension).
Using the previous solution wouldn't do this. Typing in
'http://www.myserver.com/areallystupidurl' would cause irratic behaviour
undoubtedly because of the reasons you have detailed.

The code did reach the Application_Error in the Global.asax, even though the
'error' was not from an .aspx page (it was in fact from no existent page).
So I thought that there is where I'd filter out whether to do a
Server.Transfer leave the customErrors section do its Response.Redirect.

So the 'solution' I've detailed, seems to handle non existent urls (of any
extension) and those with no extension at all, without having to access IIS.

(As I say it 'seems' to work but I'd feel more confortable if you would give
it your theoretical 'seal' of approval.... ;-) )

JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:u5**************@TK2MSFTNGP06.phx.gbl...
"JJ" <ab*@xyz.comwrote in message
news:uQ**************@TK2MSFTNGP04.phx.gbl...
>>I see that, as pointed out by Mark that Server.Transfer doesn't work for
non aspx pages.

It's not that Server.Transfer doesn't work for non aspx pages per se, but
rather that non aspx pages (e.g. *.htm etc) don't actually get processed
by ASP.NET's ISAPI DLL by default. This can be changed, but that requires
access to IIS on the webserver itself...
>This problem raises its head when you try entering a non exisitent url
without the '.aspx'.

Same problem...
>I would guess that at the 'Global.asax' level I need to check if the
referring url has a '.aspx' extension on it and if it doesn't, use
Response.Redirect instead.

See above - only files which are "recognised" by the ASP.NET ISAPI will
actually get processed by ASP.NET... If you try to access a missing HTML
file, ASP.NET won't even figure in the equation, so the contents of
Global.asax et al is completely irrelevant...
>I'm currently trying to work out how I do that....

I don't think you can, unless you can add the file extension(s) in
question to the ASP.NET ISAPI filter...
>I'm beginning to confuse myself as to why using the customErrors section
of the web.config is not enough in itself. I guess this doesn't kick in
when an unhandled expception is encountered...

See above.
--
http://www.markrae.net

May 27 '07 #14
"JJ" <ab*@xyz.comwrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...
(As I say it 'seems' to work but I'd feel more confortable if you would
give it your theoretical 'seal' of approval.... ;-) )
As I am neither a Microsoft employee nor an MVP, I have no 'seal of
approval' (theoretical or otherwise) to give you... :-)
--
http://www.markrae.net

May 27 '07 #15
JJ
Well I'll just have to run with it then... ;-)

Just don't go visiting my site and breaking it.

Thanks yet again,
JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
"JJ" <ab*@xyz.comwrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...
>(As I say it 'seems' to work but I'd feel more confortable if you would
give it your theoretical 'seal' of approval.... ;-) )

As I am neither a Microsoft employee nor an MVP, I have no 'seal of
approval' (theoretical or otherwise) to give you... :-)
--
http://www.markrae.net

May 27 '07 #16
JJ
Its a bit odd, but it turns out that my solution worked ok on my local
machines web servers, but not on the host.
So all I can do is present a polite error message for .aspx pages that are
missing, but if someone types in a url with no .aspx extension, then the
default error pages are presented,

JJ

"JJ" <ab*@xyz.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Well I'll just have to run with it then... ;-)

Just don't go visiting my site and breaking it.

Thanks yet again,
JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>"JJ" <ab*@xyz.comwrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...
>>(As I say it 'seems' to work but I'd feel more confortable if you would
give it your theoretical 'seal' of approval.... ;-) )

As I am neither a Microsoft employee nor an MVP, I have no 'seal of
approval' (theoretical or otherwise) to give you... :-)
--
http://www.markrae.net


Jun 4 '07 #17
re:
!So all I can do is present a polite error message for .aspx pages that are
!missing, but if someone types in a url with no .aspx extension, then the
!default error pages are presented,

Hi, JJ.

My question to you is : why are you trying to
catch incomplete urls at the Application level ?

I catch "regular" 404's for aspx pages in the Application_Error event,
by using server.transfer to an error.aspx page, but catch incomplete urls
with the standard 404 error page at Drive:\WINDOWS\Help\iisHelp\common.

If you want a "pretty" page for incomplete urls, just modify 404b.htm in that directory.

Check it out :

Try hitting : http://asp.net.do/test/some
....and then try hitting http://asp.net.do/test/some.aspx

The first one has a custom message for you.
The second one is caught by my Application_Error and server.transfer("Errors.aspx") routines.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message news:%2****************@TK2MSFTNGP04.phx.gbl...
Its a bit odd, but it turns out that my solution worked ok on my local machines web servers, but
not on the host.
So all I can do is present a polite error message for .aspx pages that are missing, but if someone
types in a url with no .aspx extension, then the default error pages are presented,

JJ

"JJ" <ab*@xyz.comwrote in message news:%2****************@TK2MSFTNGP05.phx.gbl...
>Well I'll just have to run with it then... ;-)

Just don't go visiting my site and breaking it.

Thanks yet again,
JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
>>"JJ" <ab*@xyz.comwrote in message news:up**************@TK2MSFTNGP05.phx.gbl...

(As I say it 'seems' to work but I'd feel more confortable if you would give it your
theoretical 'seal' of approval.... ;-) )

As I am neither a Microsoft employee nor an MVP, I have no 'seal of approval' (theoretical or
otherwise) to give you... :-)
--
http://www.markrae.net



Jun 4 '07 #18
JJ
Thanks for that - my personal 404 page in cyberspace ;-)

I guess I was trying the incorrect url entry there because that's where
incorrect .aspx pages were caught - there's logic there somewhere (I think).
I have just tried redirecting IIS's 404 error to the same page, but realise
now that IIS doesn't understand relative links so won't like a page that is
based on a master and is themed....
I guess I have to either use a straight html page or an aspx one with full
paths to images for this ?

Thanks,

JJ

"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
re:
!So all I can do is present a polite error message for .aspx pages that
are
!missing, but if someone types in a url with no .aspx extension, then
the
!default error pages are presented,

Hi, JJ.

My question to you is : why are you trying to
catch incomplete urls at the Application level ?

I catch "regular" 404's for aspx pages in the Application_Error event,
by using server.transfer to an error.aspx page, but catch incomplete urls
with the standard 404 error page at Drive:\WINDOWS\Help\iisHelp\common.

If you want a "pretty" page for incomplete urls, just modify 404b.htm in
that directory.

Check it out :

Try hitting : http://asp.net.do/test/some
...and then try hitting http://asp.net.do/test/some.aspx

The first one has a custom message for you.
The second one is caught by my Application_Error and
server.transfer("Errors.aspx") routines.



Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"JJ" <ab*@xyz.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>Its a bit odd, but it turns out that my solution worked ok on my local
machines web servers, but not on the host.
So all I can do is present a polite error message for .aspx pages that
are missing, but if someone types in a url with no .aspx extension, then
the default error pages are presented,

JJ

"JJ" <ab*@xyz.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>>Well I'll just have to run with it then... ;-)

Just don't go visiting my site and breaking it.

Thanks yet again,
JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:Oa**************@TK2MSFTNGP04.phx.gbl...
"JJ" <ab*@xyz.comwrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...

(As I say it 'seems' to work but I'd feel more confortable if you
would give it your theoretical 'seal' of approval.... ;-) )

As I am neither a Microsoft employee nor an MVP, I have no 'seal of
approval' (theoretical or otherwise) to give you... :-)
--
http://www.markrae.net




Jun 4 '07 #19
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
If you want a "pretty" page for incomplete urls, just modify 404b.htm in
that directory.
Many 3rd-party ISPs don't permit that, though...
--
http://www.markrae.net

Jun 4 '07 #20
JJ
Mine will allow me to redirect 404 errors - i.e. edit which of my pages gets
displayed for iis 404 errors for that site. I'd also hoped however, that I
could direct all these things to the same error.aspx page. Clearly not, if
that page uses relative links in any way.

Thanks,
JJ

"Mark Rae" <ma**@markNOSPAMrae.netwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>If you want a "pretty" page for incomplete urls, just modify 404b.htm in
that directory.

Many 3rd-party ISPs don't permit that, though...
--
http://www.markrae.net

Jun 4 '07 #21
re:
!Many 3rd-party ISPs don't permit that, though...

For good reason, too. That changes IIS's 404 page for all IIS apps.

That's only implementable ( is that a word ? ) when you control the server
and have a single domain on the server, or if any other domains on the
server can live with the page as modified.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:%2****************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
>If you want a "pretty" page for incomplete urls, just modify 404b.htm in that directory.

Many 3rd-party ISPs don't permit that, though...
--
http://www.markrae.net

Jun 4 '07 #22
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Many 3rd-party ISPs don't permit that, though...

For good reason, too. That changes IIS's 404 page for all IIS apps.
Are you sure about that...?
That's only implementable ( is that a word ? ) when you control the server
and have a single domain on the server, or if any other domains on the
server can live with the page as modified.
Just go into the Error pages section of each virtual directory and modify as
required...
--
http://www.markrae.net

Jun 4 '07 #23
re:
!Just go into the Error pages section of each virtual directory and modify as required.

You mean :
"just have *the ISP* go into the Error pages section of each virtual directory and modify as
required"

;-)

The client doesn't have that ability.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:OM**************@TK2MSFTNGP04.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Many 3rd-party ISPs don't permit that, though...

For good reason, too. That changes IIS's 404 page for all IIS apps.

Are you sure about that...?
>That's only implementable ( is that a word ? ) when you control the server
and have a single domain on the server, or if any other domains on the
server can live with the page as modified.

Just go into the Error pages section of each virtual directory and modify as required...
--
http://www.markrae.net

Jun 4 '07 #24
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:u6*************@TK2MSFTNGP05.phx.gbl...
re:
!Just go into the Error pages section of each virtual directory and
modify as required.

You mean :
"just have *the ISP* go into the Error pages section of each virtual
directory and modify as required"

;-)

The client doesn't have that ability.
My ISP does, though they charge for each custom error page...
--
http://www.markrae.net

Jun 4 '07 #25
re:
!My ISP does

Yup, that's what I said.

re:
!though they charge for each custom error page...

Does that surprise you ?

;-)


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
======================================
"Mark Rae" <ma**@markNOSPAMrae.netwrote in message news:ue**************@TK2MSFTNGP03.phx.gbl...
"Juan T. Llibre" <no***********@nowhere.comwrote in message
news:u6*************@TK2MSFTNGP05.phx.gbl...
>re:
!Just go into the Error pages section of each virtual directory and modify as required.

You mean :
"just have *the ISP* go into the Error pages section of each virtual directory and modify as
required"

;-)

The client doesn't have that ability.

My ISP does, though they charge for each custom error page...
--
http://www.markrae.net

Jun 4 '07 #26

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Karl A. Krueger | last post by:
I'm in the middle of refactoring a small mod_python Web application, which uses the Publisher handler. This application is currently a single main Python file (which loads several other files as...
10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
13
by: Chris Stankevitz | last post by:
Hi, I have a very large Visual c++ .net 2003 7.1 native c application (approximately 500,000 lines of code). This application is a simulation that frequently works with floating point numbers....
2
by: Marty McDonald | last post by:
Many of our apps are in production and they do not have proper error logging in them - unhandled errors are seen by the users in the form of error messages and stack traces. I know how to make...
0
by: R. MacDonald | last post by:
Hi, I have a VB.Net application that dynamically calls unmanaged routines in a DLL that has been created by Fortran (DVF v5). The call to the DLL routine is within a Try/Catch block, but when...
6
by: Harlin Seritt | last post by:
I am running the following code: import socket host = '9.9.45.103' port = 10001 conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) conn.connect((host, port))
4
by: =?Utf-8?B?SmFzb24gUmljaG1laWVy?= | last post by:
Is there a way to catch an application configuration error on startup? I have written a windows service. If there is an error in the configuration file (such as invalid xml) the exception is...
3
by: john | last post by:
I wrapped some fortran code using F2PY and need to be able to catch fortran runtime errors to run the following: # "grid" is a wrapped fortran module # no runtime errors incurred when run with...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.