Du har inte tillgång till CDONTS på servern.
ASP-kod på 404-felsida ?
49 svar · 1 137 visningar · startad av AndreasC · sida 2 av 3
Frågan, av AndreasC
Är på jakt efter en bra ASP-kod att lägga in på min 404-felsida. Koden ska skicka ett mail till en viss e-postadress om att felkod 404 har inträffat och vilken URL det gäller. Kan någon skriva ihop nåt? :)
Läs frågan i sin helhet →Ok, kan jag skriva på nåt annat sätt isåfall?
Du kan göra det i t.ex. JMail eller ASPSmartMail, men de komponenterna kan tyvärr inte jag.
Då skulle kanske solbulles script funka bättre då, det skulle visst om jag förstått det rätt, vara för ASPSmartMail.
Kan du kanske banta ner det åt mig lite grann så bara själva funktionen blir kvar. Kan ingenting om asp.
AndreasC skrev:
. Men när jag klickar på backknappen i IE och sedan på framåtknappen för att komma tillbaka så visas 404.asp som den ska men när jag kollar i källkoden så finns inte den asp-koden där som du gav mig nyss ...
Har du någonsin sett aspkoden när du visar källkoden? ;)
Vad har du för epostklient installerad på servern?
Kolla med ditt webbhotell om inte annat.
Ingen aning
Kolla med ditt webbhotell om inte annat.
Ta bort raden
[b]Server.Transfer("default.asp")[/b]
för nu får aldrig besökarna se din fina 404-sida eftersom dom skickas vidare direkt.
Du ska få ett sådant av mig lite senare idag, Där har du lite *mer* avancerade saker i.....
Tack :) Jag fick precis svar från webhotellet och de använder JMail.
Du kan leka med denna kod, byt ut asoSmartmail koden till jmail sp ska den funka på ditt webbhotell...
<% querystring=trim(replace(request.servervariables("query_string"),"404;",""))
' Grab the server varible for querystring. If the user was redirected to
' this page beacuse a file was not found the server variable query_string
' would contain a string similar to this convention
' 404;[url]http://www.yourservsername.com/name_of_missing_file.ext[/url]
' for display pirposes the 404; is removed via text replace
if querystring <> "" then %>
<font color="#FF0000" size="1" face="Verdana"><%= querystring %></font>
Hittades inte på denna server...<br>
Troligtvis beror detta på en bruten länk eller så har du
försökt gå in på en sida som inte finns på servern.<br>
<br>
<ul>
<li> Om du skrivit in adressen i adressfältet, kolla då
att du stavat rätt.</li>
<li>Öppna <a href="http://www.medialabs.nu/"><font face="Verdana">Medialabs Interactive</font></a>
och leta efter länkar till det du letar efter.</li>
<li>Klicka på <a href="javascript:history.back(1)">bakåt-knappen</a>
och testa en annan länk.</li>
</ul><br>
<p>
<%
if right(referrer,3) <> "ico" then
' Check to see if the file missing is an ico request
' IE 5 looks for it everywhere and you may want to filter it out
' as a 404 error for an favicon.ico or one with a broken link in
' LINK REL="SHORTCUT ICON" will not result in the user being redirected to this page
' Here we begin building our mail message varible
' by stating which document as missing and when the error occurred
' and follwing it with all the servervaribles (This will tell which browser
' they were using and a few other helpful items
' message = message + "Denna sida söktes men hittades inte på servern: " & now() &chr(13)
' message = message & "<br>" & querystring & "<br><br><br> Besökaren som sökte sidan:<p>"
' message = message & "IP-adress: " & request.servervariables("remote_addr")
'Dim mySmartMail
'Set mySmartMail = Server.CreateObject("aspSmartMail.SmartMail")
'mySmartMail.Server = "din.mailserver"
' From
' ****
'mySmartMail.SenderName = "404-sidan"
'mySmartMail.SenderAddress = "noreply@hej.com"
' To
' **
'mySmartMail.Recipients.Add "noreply@vadduvill", "404-sidan"
' Set the mail adress for the sender and the mail address that
' will receive the message they both should be valid addresses
'mySmartMail.Subject = "File Not Found - "& querystring
' Create a subject with name of the location that was requested
'mySmartMail.Body = message
' Set the body of the message equal to the text string created
'mySmartMail.ContentType = "text/html"
'mySmartMail.Charset = "iso-8859-1"
'mySmartMail.SendMail
' Send the mail message
end if 'End check for .ico files
else
' If a user were to directly hit your 404 error page
' without generating an error display this alternate message
%> Du har hittat till 404 sidan...<br>
Men vi kunde inte upptäcka någon bruten länk eller sida.</p>
<p><% end if 'end check of querystring values %></p>
Kan inte få det att fungera, just nu kommer inte sidan upp överhuvudtaget. Såhär ser koden ut nu:
<% querystring=trim(replace(request.servervariables("query_string"),"404;",""))
' Grab the server varible for querystring. If the user was redirected to
' this page beacuse a file was not found the server variable query_string
' would contain a string similar to this convention
' 404;[url]http://www.zelda-tlgo.com/name_of_missing_file.ext[/url]
' for display pirposes the 404; is removed via text replace
if querystring <> "" then %>
<%
if right(referrer,3) <> "ico" then
' Check to see if the file missing is an ico request
' IE 5 looks for it everywhere and you may want to filter it out
' as a 404 error for an favicon.ico or one with a broken link in
' LINK REL="SHORTCUT ICON" will not result in the user being redirected to this page
' Here we begin building our mail message varible
' by stating which document as missing and when the error occurred
' and follwing it with all the servervaribles (This will tell which browser
' they were using and a few other helpful items
' message = message + "Denna sida söktes men hittades inte på servern: " & now() &chr(13)
' message = message & "<br>" & querystring & "<br><br><br> Besökaren som sökte sidan:"
' message = message & "IP-adress: " & request.servervariables("remote_addr")
'Dim mySmartMail
'Set mySmartMail = Server.CreateObject("jmail.SmartMail")
'mySmartMail.Server = "excite.com"
' From
' ****
'mySmartMail.SenderName = "404-sidan"
'mySmartMail.SenderAddress = "haddonfield-myers@excite.com"
' To
' **
'mySmartMail.Recipients.Add "haddonfield-myers@excite.com", "404-sidan"
' Set the mail adress for the sender and the mail address that
' will receive the message they both should be valid addresses
'mySmartMail.Subject = "File Not Found - "& querystring
' Create a subject with name of the location that was requested
'mySmartMail.Body = message
' Set the body of the message equal to the text string created
'mySmartMail.ContentType = "text/html"
'mySmartMail.Charset = "iso-8859-1"
'mySmartMail.SendMail
' Send the mail message
end if 'End check for .ico files
<% end if 'end check of querystring values %>
Vad menar du med att den inte kommer upp? Kommer du inte ens till sidan? Det är ju inte så mycket synligt på den sidan om det var det du menade.
Detta är iofs fel, ta bort det första <%
<% end if 'end check of querystring values %>
Nu kommer sidan iallafall upp men det skickas inget mail.
Vad ska det stå istället för "din.mailserver" förresten? Jag har skrivit excite.com men det är kanske fel?
Jag har ändrat överallt där det står SmartMail till JMail istället men utan resultat.
För det första är den koden du håller på med samma som i den kod jag länkade till tidigt idenna tråd. - Inget mer med det iofs.
Sen vad jag kan se är all kod som har med mailet att göra utkommenterad i den kod du postar ovan, tar för givet att så inte är fallet hos dig?
Jag kan inte vare sig SmartMail eller JMail, men det skulle förvåna mig väldigt mycket om det bara är att byta ut namnen, ditt webhotell bör väl ha någon form av FAQ angående användandet av JMail, alternativ att du söker här i forumet hur du använder dig av just JMail.
Kanske låter som hårda ord, men jag menar väl. :)
Nu hittade jag ett intressant script men jag gör definitivt något fel, för precis som de script jag fått av er så kan jag inte få detta att fungera. Hela 404.asp ser ut såhär:
<% @language="vbscript" %>
<% Option Explicit %>
<%
Dim strPage, strReferer, strMessage
Dim objSMTP
' Log the offending page
strPage = Request.ServerVariables("HTTP_URL")
' Log the referer
strReferer = Request.ServerVariables("HTTP_REFERER")
' Set up the email component
Set objSMTP = Server.CreateObject("JMail.Message")
objSMTP.From = "haddonfield-myers@excite.com"
objSMTP.FromName = "Andreas Carmblad"
objSMTP.Subject = "404 Error Logged"
objSMTP.AddRecipient("haddonfield-myers@excite.com")
' Write the message
strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
If strReferer <> "" Then
strMessage = strMessage & "Referer: " & strReferer
Else
strMessage = strMessage & "The visitor typed the address in"
End If
objSMTP.Body = strMessage
' Tidy up
objSMTP.ClearRecipients
objSMTP.Close()
Set objSMTP = Nothing
%>
<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<title>404 - Page not found</title>
<link rel = STYLESHEET href = "style.css" Type = "text/css">
</head>
<body bgcolor="#ffffff">
<table border="0" cellpadding="0" cellspacing="0" width="750" summary="">
<tr>
<td valign="top" align="left" width="265">
<img src="404-1.gif" width="265" height="280" alt="">
</td>
<td valign="top" align="left" width="485">
<img src="404-2.gif" width="453" height="122" alt="">
<br><br>
<blockquote>
<font style="font-family:arial; font-size:13px; font-weight:bold">
The file you were after could not be found on our servers ...
</font>
<br><br>
<font style="font-family:arial; font-size:13px">
The requested file could not be found on this server, where one possible reason
could be that the link you just clicked on is a so called “dead link” and therefor
needs to be corrected. The URL for that link can be misspelled or maybe the page
linked to does no longer exist on the server ...
<br><br>
If you didn’t clicked on any links but instead, typed an URL by hand,
<br>make sure you didn’t typed it all wrong.
</font>
</blockquote>
</td>
</tr>
<tr>
<td valign="top" align="center" width="750" colspan="2">
<br><br>
<font style="font-family:arial; font-size:13px">
Hit the back button in your browser or click <a href="http://www.zelda-tlgo.com/" target="_top">here</a>
to re-load the site.
</font>
</td>
</tr>
</table>
</body>
</html>
Som synes så ligger asp-koden innan själva html-dokumentet börjar, så stod det att det skulle vara i exemplet.
Det som händer är att jag får IE's vanliga 404-sida, den tråkiga.
/Re Det är HTTP 500 - Internt serverfel jag får, inte 404.
Stäng av egna http-felmeddelanden / friendly error messages i IE, så borde du få ett bättre felmeddelande.
Ok.
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/404.asp, line 24
strMessage = strMessage "The visitor typed the address in"
Ock vad exakt är fel på den raden?
