DEV Community

Cover image for Microsoft Officially Supports Rust Powered Web Framework

Microsoft Officially Supports Rust Powered Web Framework

sharpninja profile image The Sharp Ninja ・3 min read

Microsoft is at it AGAIN!

What if I told you that there's a thoroughly designed and tested web framework that is ready for #Rust today? It's completely ready to go with a high-performance web server, several identification and authorization schemes and a very flexible templating engine that you can use today!

This amazing web framework is called Active Server Pages, and it's perfect for creating Web Apps in Rust utilizing the Windows-RS project which provides COM bindings for Rust. Since Active Server Pages was developed for compiled code in COM objects, this is a natural fit!

First, follow the instructions to set up your Windows environment for developing with Rust.

Next, install Active Server Pages on your Windows machine.

# * Make sure you run this script from a Powershel Admin Prompt!
# * Make sure Powershell Execution Policy is bypassed to run these scripts:
Set-ExecutionPolicy Bypass -Scope Process

Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerRole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServer
Enable-WindowsOptionalFeature -Online -FeatureName IIS-CommonHttpFeatures
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpErrors
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpRedirect
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationDevelopment

Enable-WindowsOptionalFeature -Online -FeatureName IIS-HealthAndDiagnostics
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpLogging
Enable-WindowsOptionalFeature -Online -FeatureName IIS-LoggingLibraries
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestMonitor
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpTracing
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Security
Enable-WindowsOptionalFeature -Online -FeatureName IIS-RequestFiltering
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Performance
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WebServerManagementTools
Enable-WindowsOptionalFeature -Online -FeatureName IIS-IIS6ManagementCompatibility
Enable-WindowsOptionalFeature -Online -FeatureName IIS-Metabase
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ManagementConsole
Enable-WindowsOptionalFeature -Online -FeatureName IIS-BasicAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-WindowsAuthentication
Enable-WindowsOptionalFeature -Online -FeatureName IIS-StaticContent
Enable-WindowsOptionalFeature -Online -FeatureName IIS-DefaultDocument
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ApplicationInit
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIExtensions
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ISAPIFilter
Enable-WindowsOptionalFeature -Online -FeatureName IIS-HttpCompressionStatic
Enable-WindowsOptionalFeature -Online -FeatureName IIS-ASP
Enter fullscreen mode Exit fullscreen mode

After the script runs you'll be ready to host your Active Server Pages on port 80. The default location for your files is C:\inetpub\wwwroot. Just open a browser to http://localhost and you should get a default page. Go blow away the contents of the wwwroot folder and create a new file calle default.asp.

Title = "Awesome New Scripting Platform!"

Max = CLng("0" & Request("Max"))

If Max = 0 Then Max = 5
<!DOCTYPE html>
    <title><%= Title %></title>
<h1>Count to <%= Max %>...</h1>
    Response.Write "<h2>Session: " & Session.SessionID & "</h2>"

    Dim counter

    For counter = 1 To Max
        Response.Write "<li>" & counter & "</li>"
Enter fullscreen mode Exit fullscreen mode

What's going on here?

Well, we have created an Active Server Page that uses the default scripting language to read a query string value called max and then count to that number. If no value was supplied, we count to five.

We've also displayed the Session ID created by the application using the Response object which handles output to the browser.

Everything between <% %> is a code block. To write to the browser from inside the code block use the Response.Write function. You can also interleave HTML and code blocks. We can also directly write the value of an expression using <%= %> inline to the HTML template.

Interleaving Code and Script

<h1>Count to <%= Max %>...</h1>
    Response.Write "<h2>Session: " & Session.SessionID & "</h2>"

    Dim counter

    For counter = 1 To Max %>
        <li><%= counter %></li>
<%  Next %>
Enter fullscreen mode Exit fullscreen mode

Next time we'll create a Rust data object and display it in our template. Be sure to tell me what you think of this web framework. It's so much lighter than React or Vue and renders server side for maximum performance! What kind of applications will you build with Active Server Pages and Rust?

Discussion (1)

davidedelpapa profile image
Davide Del Papa

This post does not talk about how to integrate Rust to ASP. Can you lengthen it a little, showing the Rust implementation?

Forem Open with the Forem app