global.aspx Application_error does not fire on anything other than

J

jvcoach23

I've got a global.aspx file that works in my dev environment (vs 2005).
When i publish the site to a windows 2000 sp4 box running IIS, the global
does not seem to fire. Since it's a test server, i've tried granting the
user that IIS is using with all kinds of rights, that didn't work.... so is
there some setting i'm missing somewhere.

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
Dim olog As New dempsey.TextFile
With olog
.FileName = "500Errors.txt"

..SaveText("-------------------------------------------------------------")
Dim err As Exception = Server.GetLastError()

.SaveText(Err.ToString)
.SaveText(err.StackTrace)
End With

Response.Redirect("~/500Error.htm")
end sub

and an bit from the web.config file
<compilation debug="false" strict="false" explicit="true">

hope someone can help out...
just to be more complete.. in the appliction_error, i'm also writing some
info out to a sql database... again.. that works running things out of visual
studio.. but not when the code is published..

thanks
shannon
 
J

jvcoach23

I'll try that..

I don't think the sql logging is causing any problems. I'm using a class to
write to the database, this class is using the same connection string that
all the other database calls are using and i'm able to do inserts for those.
i've watched in sql profiler and the sql box is not getting hit by the this
call... so i don't think it's firing... i understand though that if it was
getting chocked up on this, that it would make the call.. i've also tried
writing out to a log file, again, that works when running in visual studio,
but not when it is published.
 
S

Shannon

Hi Peter.. another question

what is a way that i can test.. or trap if there is something causing the
application_error to bomb.. i mean.. if i have something wrong with my code
or something else is going wrong, what is the best way to figure that out...

if the application_error is running, but i'm bombing out on some of my
code.. what is somethign that i can put in there to test to see if it's
running. i'll commit out all my code

hopefully that way i can give you better info so you can set me straight..

thanks
shannon
 
J

Juan T. Llibre

re:
!> any other suggestions

1. Make sure the ASPNET account in the W2K server
( if you're not impersonating ASP.NET's account ),
which is the default account ASP.NET runs as under W2K,
has write permissions to the directory where 500Errors.txt is being written to.

If you don't know which account ASP.NET runs as in the W2K server,
save this code as "identity.aspx" and run it on the W2K server.

identity.aspx:
-------------------
<%@ Page Language="VB" %>
<%@ Import NameSpace = System.Security.Principal %>
<script runat="server">
Sub Page_Load()
Dim tmp As String = WindowsIdentity.GetCurrent.Name()
Label1.Text = "ASP.NET is running as the account : " & tmp
End Sub
</script>
<html>
<head>
<title>What account is ASP.NET running as ?</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" Runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
------------

Whichever account that code returns is the account which needs permissions.

2. Make sure the account returned by identity.aspx has the
specific access permissions for the directories listed in this article:

ASP.NET Required Access Control Lists (ACLs)
http://msdn2.microsoft.com/en-us/library/kwzs111e.aspx

3. Register-unregister ASP.NET in IIS, by running aspnet_regiis
from a command window in the .Net Framework's 2.0 directory :

First unregister :

aspnet_regiis -u

Then, re-register :

aspnet_regiis -i

That will first delete and then recreate the ASP.NET account,
assigning the necessary permissions to that account.

I'd find it very strange if global.asax wouldn't fire,
if you have a healthy .Net Framework installation.

If none of these suggestions work, I'd uninstall the .Net Framework 2.0,
using the Add/Remove Programs applet in Control Panel...and reinstall it fully.
 
S

Shannon

thanks...
i had seen that identity page tip somewhere else.. the account that the test
box is using is ASPNET and i added that user to the administrator group.. i
understand that i won't want to do that in production, but in an effort to
try to figure out what i'm doing wrong so that the global is not working, i
thought that should open the door pretty wide..

do you have any other suggestions
thanks
shannon
 
J

Juan T. Llibre

re:
!> i had seen that identity page tip somewhere else...

Probably somewhere where I posted...or where someone posted my code without attribution.
I wrote that ditty. :)

re:
!> do you have any other suggestions

Run through the list of directories in the article link I posted,
and make sure the ASPNET account has the listed permissions.

As mentioned earlier, there's no reason for global.asax not to fire,
and for Application_Error not to fire, too, if you have a healthy install
of the .Net Framework and the .Net Framework is registered with IIS,
particularly if, as you say, the same code works in a test environment.

If none of the suggestions work, and unless the W2K server's admin
has explicitly forbidden the use of global.asax, uninstalling and reinstalling
the .Net Framework is the only recourse left.

Talk to the W2k server's admin...and see what (s)he says.
 
S

Shannon

ok.. i'll get to work on that.. i'm the admin of the IIS box.. it's just a
test box that is running on it's own workgroup... I've got the 1.1 and 2.0
framework installed on the box...

I'll go through that link.. and post what happens...

thanks
 
J

jvcoach23

the user that the
website is running under is ASPNET. that user has the rights that the
article describes... except for this line.. i'm not sure if about it

User profile directory
Used by the GAC cache lock files and the security configuration caching
mechanism of the common language runtime. If the user profile directory for
the account does not exist, ASP.NET uses the default user profile
directory.

i added the user with rigts to the the C:\Documents and Settings\SERVER1
dir (server1/aspnet is the user that shows up when i run the identity page)

so then i uninstalled .net 1.1 and 2.0... uninstalled iis.
reinstalled 1.1 and 2.0. then reinstalled iis

created the application in iis
published the website
had to run aspnet_regiis -i in the 2.0 framework and the website runs, but
the global still is not "working"

what kind of troubleshooting steps can i take to see if the global really
is working but what i'm asking it to do inside the application_error is
bombing, or if the global itself isn't working.

any suggestion would be great
thanks
shannon
 
J

Juan T. Llibre

Here's a simple test...

Include this in global.asax :

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

Include this in "errors.aspx" :

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>
<asp:label id="ErrorMessage" font-size="12" font-bold="true" runat=server/>
</body>
</html>
--------------

Finally, inside the system.web section of web.config, include this :

<customErrors mode="On" />

To test, write any invalid URL in the address bar...and see if you get the custom message.
That will tell you whether Global.asax, and Application_Error within it, are firing.
 
J

jvcoach23

i did as you suggested... added the code to the application_error and
commented out all my code that was in that sub

added the new page

modified the web.config file

when i hit the page that does not exists, i get a page "The page cannot be
found" error. i do not get redirected.

so after having checked the rights for the user, uninstalling and
reinstalling .net and IIS, what is the next step in the troubleshooting
list.

thanks again for all the pointers and help. Hope you can continue to help
me through this.

thanks
shannon
 
J

Juan T. Llibre

re:
!> Another option is to simply set a custom page for 404 errors in IIS.

404s for html, asp, etc. are handled "out of the box" by IIS,
without the need for a custom page for 404 errors, but .aspx files are not.

Remember, .aspx files go through the ASP.NET ISAPI application; html, asp, etc. files don't.

You're right, though, that is an option...for html files, for .asp files and,
in general, for any file that doesn't go through the ASP.NET ISAPI app.
 
J

jvcoach23

Here is the sub

Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Server.Transfer("~/Errors.aspx")
'some commented out code
End Sub

and the name of the file it's going to is Errors.aspx.. all the code in the
files is as you had.

I've double checked, republished and i'm getting teh page cannot be found
message.. The redirect never takes place.

your code does redirect when i run it from vb.

again.. thanks for the help.. hope your willing to continue
thanks
shannon
 
J

jvcoach23

yep.. i understand what your saying. but in the global.asax file, i have
some code to gather some info and store it to a database... that's why i am
trying to go this route..

thanks for the input though
shannon
 
J

jvcoach23

ok.. the server.transfer seems to be working.. kind of.. need some
education here.

I loaded up sysinternals file monitor to see if i could better understand
if there was an access error. that is where i noticed that i was trying
to hit a file with an extension of aspx1... i put the 1 in my link to make
the file so that it was not found.. but after the post talking about the
html vs the aspx, i changed the dead link to be an aspx extension instead.

I republished and now i click on the dead link and the address bar shows
the dead link url, but the message on the screen is

The page you have requested can't be found.
We're sorry for the inconvenience.

from the page that i created per the advice of someone on this thread. so,
the server.transfer("~/Errors.aspx") verbage is showing up, but the url is
the dead link... does that sound correct.

i'm gonna put my code back in and keep on trying things.. just didn't want
someone running up the wrong tree trying to help guide me.. hoping somone
can still education me on the server.transfer and addresss line thing
mentioend above.

thanks
shannon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top