Skip to content

ASP.Net

github-actions[bot] edited this page Oct 15, 2025 · 4 revisions

ASP.NET Core Setup

ASP.NET Core remains the recommended approach for complex web applications with ElectronNET.Core, providing all the benefits of the ASP.NET ecosystem along with enhanced Electron integration.

🛠 System Requirements

See System Requirements.

🚀 Quick Start

1. Create ASP.NET Core Project

Create a new ASP.NET Core Web App in Visual Studio:

dotnet new webapp -n MyElectronWebApp
cd MyElectronWebApp

2. Install NuGet Packages

PM> Install-Package ElectronNET.Core
PM> Install-Package ElectronNET.Core.AspNet

Note

ElectronNET.Core.AspNet provides ASP.NET-specific runtime components and should be used alongside ElectronNET.Core.

3. Configure Program.cs

Update your Program.cs to enable Electron.NET:

using ElectronNET.API;
using ElectronNET.API.Entities;

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        builder.Services.AddRazorPages();

        // Add this line to enable Electron.NET:
        builder.UseElectron(args, ElectronAppReady);

        var app = builder.Build();

        if (!app.Environment.IsDevelopment())
        {
            app.UseExceptionHandler("/Error");
        }
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthorization();

        app.MapRazorPages();

        app.Run();
    }

    public static async Task ElectronAppReady()
    {
        var browserWindow = await Electron.WindowManager.CreateWindowAsync(new BrowserWindowOptions { Show = false });

        browserWindow.OnReadyToShow += () => browserWindow.Show();
    }
}

ASP.NET Port

If you want to launch a specific URL, you can retrieve the actual ASP.NET port from the new ElectronNetRuntime static class, for example:

    await browserWindow.WebContents
        .LoadURLAsync($"http://localhost:{ElectronNetRuntime.AspNetWebPort}/mypage.html");

4. Alternative: IWebHostBuilder Setup

For projects using the traditional Startup.cs pattern, please see "Traditional ASP.NET Core" in the Migration Guide.

🚀 Next Steps

💡 Benefits of ASP.NET + Electron

Full Web Stack - Use MVC, Razor Pages, Blazor, and all ASP.NET features
Hot Reload - Edit ASP.NET code and see changes instantly
Rich Ecosystem - Access to thousands of ASP.NET packages
Modern Development - Latest C# features and ASP.NET patterns
Scalable Architecture - Build complex, maintainable applications

Clone this wiki locally