NMath User's Guide

TOC | Previous | Next | Index

1.8 Web Applications (.NET, C#, CSharp, VB, Visual Basic, F#)

You can create ASP.NET web applications using NMath, just like any other .NET application. However, there are a few additional considerations for building and deploying ASP.NET applications.

Referencing NMath

To use NMath types in your web application, add a reference to NMath.dll, just as you would with other types of .NET applications. If you are using web projects in Visual Studio, you can simply right-click the References folder, and select the Add Reference… command. If you specify Copy Local equals true in the reference's properties, then the assembly will be copied to the /bin directory of the web application, facilitating deployment to a web server.

If you are not using web projects in Visual Studio—if you are using the Open Web Site command in Visual Studio, for example, or are using other development tools— you can alternatively specify the reference in the web.config file:

        <add assembly="NMath, Version=<Version>, Culture=neutral, 

We recommend that you do not add references to the kernel assemblies, as the appropriate kernel assembly for your platform is loaded at runtime and the appropriate native DLL is linked to the kernel.

Kernel Assemblies and Native DLLs

For ASP.NET applications, Microsoft recommends that the /bin directory contain only .NET assemblies, not native DLLs.

If the deployment web server may not have NMath installed directly, then we recommend that the native DLLs be placed in a folder within the web application root directory, such as /NativeBin. This folder should then be copied to the deployment web server along with the rest of your application.

NMath Configuration

NMath settings can be configured as described in Section 1.6. However, when deploying web applications, especially to a shared hosting environment, it's quite common not to know the details of the physical structure of the file system, and to have restricted access to the system's environment variables. The references to resources within web applications are typically relative to the root of the virtual directory for the website, regardless of where they might physically reside on disk.

For this reason, the ASP.NET ~ operator can be used to specify the location of the NMath native libraries and the log file, relative to the web application root. That is, these can be specified in the web.config file like so:

<add key="NMathNativeLocation" value="~/NativeBin" />
<add key="NMathLogLocation" value="~/Logs" />

It is not sufficient to use relative paths, such as bin/, since the executing assembly is usually the ASP.NET worker process. Depending on the web server configuration, the working directory is usually a subdirectory of the Windows system directory (such as c:\windows\system32).

NOTE—The ~ operator can only be used in ASP.NET applications; specifying this in a Windows application will cause the path to be resolved incorrectly.