SmartAssembly

Latest version: 6.7

SmartAssembly

Knowledge Base

Protecting website code using SmartAssembly

Category: How do I?
Date: 13 Oct 2011
Product: SmartAssembly
SmartAssembly can only protect precompiled .NET assemblies, whereas traditionally, ASP .NET websites are dynamically compiled on the server as needed. This makes it unclear how to protect a website with SmartAssembly.

The solution this problem is to precompile the website. The .NET Framework ships with a utility for this purpose called aspnet_compiler.exe. This will create a series of DLLs from your website code and placeholder files from the original code files, so the original code is no longer available in the website folder. Once the compilation is complete, you may protect the resulting DLLs in the bin folder using SmartAssembly. If you are also implementing error reporting, you must protect all dlls separately, as merging and embedding seem to break the error reporting function.

To implement SmartAssembly protection and error reporting in ASP .NET, follow these steps:

  · Add a reference to c:\program files\red gate\smartassembly 6\SDK\bin\SmartAssembly.ReportException.dll in the web project
  · Open the codebehind file for Global.asax (Global.aspx.cs) in Notepad or Visual Studio
  · If the method protected void Application_Error(Object sender, EventArgs e) does not exist, create it
  · The method should contain these lines
     

  1. [C#]
  2.                 Exception exc = Server.GetLastError().GetBaseException();
  3.                 SmartAssembly.ReportException.ExceptionReporting.Report(exc);
  4.           [/C#]

     
  1. [VB]
  2.                 Dim exc As Exception = Server.GetLastError().GetBaseException()
  3.                 SmartAssembly.ReportException.ExceptionReporting.Report(exc)
  4.           [/VB]


  · Save Global.asax.cs (or vb)
  · Use Aspnet_Compiler to create pre-compiled code for the website
(aspnet_compiler -v "/" -d -p "c:\mywebsite" "c:\mynewwebsite")
  · Open the dependent DLLs (not App_Web_xxx.dll) and create an SA project for each
    · Set up error reporting to report silently
    · Build the DLL into a new folder in a "bin" subfolder (c:\mynewSAwebsite\bin)
  · Open the main DLL in a new SmartAssembly project (App_Web_xxx.dll)
    · Set up error reporting as for the dependent DLLs, but do not merge or embed the dependencies.
   · Copy all of the files that are not DLLs from the original compiled website to the one you just created
      (xcopy c:\mynewwebsite c:\mynewSAwebsite /E /EXCLUDE:\bin\)

The compiled and protected website is now available in the c:\mynewSAwebsite folder. Configuring this folder as an IIS web application will make it available to users of your website.

Document ID: KB201110000519 Keywords: SmartAssembly,ASP,error,reporting

Was this article helpful?

Search support
Forums
Visit the SmartAssembly forum.

SmartAssembly

all products