Technical Article

View/Edit ASP Script from From SQL Server 7.0/2000

,

Ever want to display (and edit) ASP code from the original .asp file?  (like PHP's PHPInfo() function).

To setup:
  * Just create a .asp with SQL Server connectivity.
  * Change @IISHostNameWWWPath to match your servername
     -OR-
    if SQL Server is on the same machine, use the next
    line instead. (see script)
  * Edit your .asp page to pass
      Request.ServerVariables("PATH_INFO")
      to usp_ViewASP procedure.

One cool enhancement would be to check to see if the person has (let's say) a asp_developers role in the database.  You could create a page to allow only special users to view/edit the code, within the browser!

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE PROCEDURE usp_ViewASP(@strFile VARCHAR(255))
AS
   /***
    *   Date:         4/22/2002
    *   Author:       <mailto:mikemcw@4segway.biz>
    *   Project:      Developer Tools
    *   Location:     Any Database
    *   Permissions:  PUBLIC EXECUTE.
    *   
    *   Description:  Will display your .asp code or any other file.
    *                 Good for debugging database and asp or .net code.
    *
    *   Restrictions: If the \\servername is used
    *   
    *   Security:     Caution @strFile could contain harmful code.
    *                 Application should not allow free hand, user
    *                 entered filename into @strFile.
    *   
    *   Enhancements: Could do a search for harmful characters and
    *                 return an error if found.
    *   
    *   History:
    *   
    *   Usage:        Pass the value of:
    *                     Request.ServerVariables("PATH_INFO")
    *                 to this stored proc from your ASP page.
    *                 
    *                 
    *   Example:      usp_ViewASP '/hmdb/default.asp'
    *   Returns:      The raw script from that .asp page.
    *   
    *   Other:        Works with any text file
    *   
    ***/BEGIN
  DECLARE @IISHostNameWWWPath VARCHAR(255)
  SET @IISHostNameWWWPath = '\\IISservername\c$\inetpub\wwwroot'
  --OR:  SET @IISHostNameWWWPath = '\c:\inetpub\wwwroot'

  SET @strFile = @IISHostNameWWWPath + REPLACE(@strFile,'/','\')

  SELECT @strFile = 'master..xp_cmdshell ''Type ' + @strFile + ''''
  EXECUTE ( @strFile )  --get the users on the domain
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating