Integrazione col tuo web server ASP
A cura di Roberto Castaldo | sabato 7 settembre 2002
Link permanente
Questa appendice descrive alcuni passi che potrebbero tornarti utili se volessi inserire la validazione all’interno di un web server ASP - come Internet Information Server (IIS) di Microsoft.
Innanzitutto, installa il validatore SP in una nuova cartella all’interno della cartella radice della tua intranet. Per esempio, potresti chiamarla ‘executables’, come puoi vedere nella figura qui sotto.

» La figura illustra un possibile layout di cartelle nel tuo web server.
Assicurati che la nuova cartella sia configurata come cartella eseguibile.
Ricorda, inoltre, di impostare le autorizzazioni di file/cartella per l’”utente” IWAM_<server name>, cosi che “egli” sia in grado di accedere ai files da validare. Inoltre l’”utente” IWAM_<server name> dovrà anche avere il permesso di esecuzione rispetto alla cartella che contiene nsgml.exe.
Io stesso non sono un amministratore di web server, quindi fai molta attenzione nell’alterare le impostazioni di sicurezza del tuo web.
Crea un file ASP validate.asp che salverai in un’altra cartella, per esempio quella che chiamerai ‘validate’, come nella figura di sopra. Ecco il codice del file validate.asp:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Validazione</title>
<meta name="author" content="Michael Suodenjoki" />
<meta name="description" content="Validate Service" />
<meta name="keywords" content="validate,validation,service,correctness,wellformness" />
<meta name="robots" content="index,follow" />
<!--#include virtual="/include/styles.inc"-->
</head>
<body>
<!--#include virtual="/include/header.inc"-->
<h1>Servizio di Validazione</h1>
<div class="box180">
Usefull links:
<ul>
<li><a href="http://www.htmlhelp.com/reference/html40/alist.html">Elementi HTML 4.0 (Ordine alfabetico)</a></li>
</ul>
</div>
<p>La pagina seguente è stata validata per XHTML :</p>
<%
Response.Write("<p>http://" & Request.ServerVariables("SERVER_NAME") & Request.QueryString("url") & "</p>")
Dim sValidateFile
sValidateFile = Server.MapPath(Request.QueryString("url"))
' Debug messages (currently outcommented)
'Response.Write("<p>" & Request.QueryString("url") & "</p>")
'Response.Write("<p>" & sValidateFile & "</p>")
'Response.Write("<p>" & Request.ServerVariables("SCRIPT_NAME")& "</p>")
'Response.Write("<p>" & Server.MapPath(Request.ServerVariables("SCRIPT_NAME")) & "</p>")
Dim oWSH,sCmdLine
Set oWSH = Server.CreateObject("WScript.Shell")
' Messaggio di debug(attualmente commentato)
'Response.Write("Eseguibile: " & Server.MapPath("/executables/nsgmls.exe") & "<br/>" )
' Crea un nome di file temporaneoe (usato per l'output)
Dim oFSO ' Come oggetto- FileSystemObject.
Dim sTempFile ' Come stringa - nome di file temporaneo
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
sTempFile = Server.MapPath("/executables") & "" & oFSO.GetTempName()
' Costruisce la riga di comando
'
' Example:
' C:ValidatorSPbinnsgmls -s -c C:ValidatorSPpubtextxhtml.soc -f %TEMP%validation-results.txt %1
'
sCmdLine = Server.MapPath("/executables/nsgmls.exe") & " -s" & _
" -c " & Server.MapPath("/executables/pubtext/xhtml.soc") & _
" -f " & sTempFile & _
" """ & sValidateFile & """"
' Debug output - write command line...
'Response.Write("<p>Command line: "" & sCmdLine & ""</p>" )
' Execute the command line
Call oWSH.Run(sCmdLine,1,True)
'Call oWSH.Run("notepad.exe",5,False)
%>
<%
' Read the result and present it
Dim oFile
Set oFile= oFSO.OpenTextFile(sTempFile, 1) '1=ForReading
Dim sResult
If oFile.AtEndOfStream <> True Then
sResult = oFile.ReadAll()
End If
'Response.Write("<div>" & sResult & "</div>" )
oFile.Close
Set oFile = oFSO.OpenTextFile(sValidateFile,1) '1=ForReading
Dim sSource
sSource = oFile.ReadAll()
oFile.Close
' Delete the temporary file...
oFSO.DeleteFile(sTempFile)
Set oFSO = Nothing
Set oWSH = Nothing
%>
<h2>Validation Result</h2>
<%
Dim sSourceLines
sSourceLines = Split(sSource,vbCrLf)
Dim sLines, nLastLine
sLines = Split(sResult, vbCrLf)
nLastLine = ubound(sLines)
'
' 'Report Error'
'
' This function parses a SGML error line and reports it in a more nice way.
'
Function ReportError( sErrorLine )
Dim sElems
sElems = Split(sErrorLine, ":" )
' 0 = sElems(0) = Drive of exe
' 1 = sElems(1) = File name of exe
' 2 = sElems(2) = Drive of web page
' 3 = sElems(3) = File name of web page file
' 4 = sElems(4) = Line number
' 5 = sElems(5) = Column
' 6 = sElems(6) = Type of error 'E' = error
' 7 = sElems(7) = Error Message
If sElems(2)="E" Then
Response.Write( "<p>Error: " & sElems(3) & ":" & sElems(4) & "</p>" )
Else
If sElems(6)="E" Then
Response.Write( "<li>Line <a href='#" & sElems(4) & "'>" & sElems(4) & "</a> Column " & sElems(5) & " - " )
Response.Write( "Error: " )
If 7 <= ubound(sElems) Then
Response.Write( sElems(7) )
End If
Response.Write( "</li>" )
Response.Write( "<blockquote class='syntax'>" )
Response.Write( Replace(sSourceLines(sElems(4)-1),"<","<") & "<br/>" )
Response.Write( Replace(Space(sElems(5))," "," ") & "<span style='color:red'>^</span>" )
Response.Write( "</blockquote>" )
End If
End If
End Function
'
' 'ReportErrors'
'
' Function to reports errors from a SGML output file (assuming these a present in sLines array.
'
Function ReportErrors()
nLine = 0
While nLine < nLastLine
Call ReportError(sLines(nLine))
'Response.Write nLine & ": " & sLines(nLine) & "<br/>"
nLine=nLine+1
Wend
End Function
If nLastLine > 0 Then
Call ReportErrors()
Else
Response.Write("<p>No Errors Found.</p>")
End If
%>
<h2>Source Listing</h2>
<p>Below is the source input used for this validation:</p>
<pre class="syntax">
<%
nLastLine = ubound(sSourceLines)
nLine = 0
While nLine < nLastLine
Response.Write "<a name=" & nLine+1 & ">" & nLine+1 & "</a>: " & Replace(sSourceLines(nLine),"<","<") & "<br/>"
nLine=nLine+1
Wend
%>
</pre>
<!--webbot bot="PurpleText" PREVIEW="Footer Included Here..." -->
<!--#include virtual="/include/footer.inc"-->
</body>
</html>
Per validare una pagina web, devi fornire a validate.asp il parametro url, per esempio:
http://www.myweb.com/validate.asp?url=/files_to_check/mypage.html
Spero che il tutto possa esserti utile.











