Help. ReactJS ASP.NET Core doesn't work Electron.NET #838

Closed
opened 2026-01-29 16:49:51 +00:00 by claunia · 1 comment
Owner

Originally created by @maguro1kan on GitHub (Dec 31, 2022).

Hi. I trying ReactJS ASP.NET Core with .NET 6.
Build successed, but blank page showed. I want to show ReactJS ASP.NET core original page.

Firstly, I created new project in VS2022. Then installed ElectronNET.API by nuget.

Program.cs

using ElectronNET.API;

namespace TheBestNamespace
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseElectron(args);
                webBuilder.UseEnvironment("Development");
                webBuilder.UseStartup<Startup>();
            });
    }
}

and Added Startup.cs

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

namespace TheBestNamespace
{
	public class Startup
	{
		public Startup(IConfiguration configuration)
		{
			Configuration = configuration;
		}

		public IConfiguration Configuration { get; }

		// This method gets called by the runtime. Use this method to add services to the container.
		// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
		public void ConfigureServices(IServiceCollection services)
		{
			//services.AddSingleton(sg => { var log = sg.GetService<ILogger<Startup>>()});
			services.AddRazorPages();
			//services.AddServerSideBlazor();
			//services.AddSingleton<MyService>(); // Other singletons
		}

		// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
		public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
		{
			if (env.IsDevelopment()) 
			{
				app.UseDeveloperExceptionPage();
			} else 
			{
				app.UseExceptionHandler("/Error");
				// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
				app.UseHsts();
			}

			//app.UseHttpsRedirection(); // disabled in project settings webserver too.
			app.UseStaticFiles();
			app.UseRouting();

			// For blazor
			//app.UseEndpoints(endpoints => 
			//{
			//		endpoints.MapBlazorHub();
			//		endpoints.MapFallbackToPage("/_Host");
			//});

			// For regular
			app.UseEndpoints(endpoints =>
			{
				//endpoints.MapRazorPages();
                endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action=Index}/{id?}");
            });


			if (HybridSupport.IsElectronActive)
			{
				Console.WriteLine("Creating electron window");
				ElectronCreateWindow();
			}
		}

		public async void ElectronCreateWindow()
		{
			var browserWindowOptions = new BrowserWindowOptions
			{
				Width          = 1024,
				Height         = 768,
				Show           = false, // wait to open it
				WebPreferences = new WebPreferences
				{
					WebSecurity = false
				}
			};

			var browserWindow = await Electron.WindowManager.CreateWindowAsync(browserWindowOptions);
			await browserWindow.WebContents.Session.ClearCacheAsync();

			// Handler to show when it is ready
			browserWindow.OnReadyToShow += () =>
			{
				browserWindow.Show();
			};

			// Close Handler
			browserWindow.OnClose += () => Environment.Exit(0);
		}
	}
}

Two codes from HERE

SS
SS2

Sorry, my English isn't good.
Thanks.

Originally created by @maguro1kan on GitHub (Dec 31, 2022). Hi. I trying ReactJS ASP.NET Core with .NET 6. Build successed, but blank page showed. I want to show ReactJS ASP.NET core original page. Firstly, I created new project in VS2022. Then installed ElectronNET.API by nuget. Program.cs ``` using ElectronNET.API; namespace TheBestNamespace { public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseElectron(args); webBuilder.UseEnvironment("Development"); webBuilder.UseStartup<Startup>(); }); } } ``` and Added Startup.cs ``` using ElectronNET.API; using ElectronNET.API.Entities; namespace TheBestNamespace { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { //services.AddSingleton(sg => { var log = sg.GetService<ILogger<Startup>>()}); services.AddRazorPages(); //services.AddServerSideBlazor(); //services.AddSingleton<MyService>(); // Other singletons } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } //app.UseHttpsRedirection(); // disabled in project settings webserver too. app.UseStaticFiles(); app.UseRouting(); // For blazor //app.UseEndpoints(endpoints => //{ // endpoints.MapBlazorHub(); // endpoints.MapFallbackToPage("/_Host"); //}); // For regular app.UseEndpoints(endpoints => { //endpoints.MapRazorPages(); endpoints.MapControllerRoute(name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); if (HybridSupport.IsElectronActive) { Console.WriteLine("Creating electron window"); ElectronCreateWindow(); } } public async void ElectronCreateWindow() { var browserWindowOptions = new BrowserWindowOptions { Width = 1024, Height = 768, Show = false, // wait to open it WebPreferences = new WebPreferences { WebSecurity = false } }; var browserWindow = await Electron.WindowManager.CreateWindowAsync(browserWindowOptions); await browserWindow.WebContents.Session.ClearCacheAsync(); // Handler to show when it is ready browserWindow.OnReadyToShow += () => { browserWindow.Show(); }; // Close Handler browserWindow.OnClose += () => Environment.Exit(0); } } } ``` Two codes from [HERE](https://github.com/ElectronNET/Electron.NET/issues/685) ![SS](https://user-images.githubusercontent.com/30754124/210126889-fad24dd1-701e-49de-a7c4-b29ceb6bb55e.JPG) ![SS2](https://user-images.githubusercontent.com/30754124/210126918-847ff7fb-6f37-41a4-a228-a7e4541d38fc.JPG) Sorry, my English isn't good. Thanks.
claunia added the question label 2026-01-29 16:49:51 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Mar 28, 2023):

🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉

With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!

@GregorBiswanger commented on GitHub (Mar 28, 2023): 🎉🚀 New Electron.NET version 23.6.1 released 🚀🎉 With native Electron 23 and .NET 6 support. Your problem should be fixed here. If you continue to have the problem, please let us know. Please note the correct updating of your API & CLI. Info in the README. Have fun!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#838