SmartAssembly 8

Using SmartAssembly with an ASP.NET website

ASP.NET websites are dynamically compiled on the server as needed but SmartAssembly can only protect precompiled .NET assemblies. This makes it unclear how to protect a website with SmartAssembly.

The solution 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 placeholders, so the original code is no longer available in the website folder. Once the compilation is complete, you protect the resulting DLLs in the bin folder using SmartAssembly.

If you're also implementing error reporting, you must protect all dlls separately, as merging and embedding may break the error reporting function.

To implement SmartAssembly protection and error reporting in ASP.NET:

  1. Add a reference to %ProgramFiles%\Red Gate\Smartassembly 8\SDK\bin\SmartAssembly.ReportException.dll in the web project. 
  2. Open the codebehind file for Global.asax (Global.aspx.cs) in Notepad or Visual Studio.
  3. If the method protected void Application_Error(Object sender, EventArgs e) does not exist, create it. 
    The method should contain these lines:

    (C#)

    Exception exc = Server.GetLastError().GetBaseException();
    SmartAssembly.ReportException.ExceptionReporting.Report(exc);

    (VB)

    Dim exc As Exception = Server.GetLastError().GetBaseException()
    SmartAssembly.ReportException.ExceptionReporting.Report(exc)
  4. Save Global.asax.cs (or vb) 
  5. Use Aspnet_Compiler to create pre-compiled code for the website:

    aspnet_compiler -v "/" -d -p "c:\mywebsite" "c:\mynewwebsite"
  6. Open the dependent DLLs (not App_Web_xxx.dll) and create a SmartAssembly project for each.
  7. If you are using Automatic Error Reporting, set it to report errors silently.
  8. Build the DLL in a new folder in a bin subfolder (for example, C:\mynewSAwebsite\bin).
  9. Open the main DLL (App_Web_xxx.dllin a new SmartAssembly project.
  10. Set up error reporting as for the dependent DLLs, but do not merge or embed the dependencies.
  11. 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. Configure this folder as an IIS web application to make it available to users of your website.


Didn't find what you were looking for?