Running a localhost ASP.NET web server via Tizen C# NUI application

48 Views Asked by At

I have a basic Tizen NUI application with just a web view inside. The web view is just supposed to show a web server that I created.

// from TizenApp solution
internal class Program : NUIApplication
    {
        protected override void OnCreate()
        {
            base.OnCreate();
            Initialize();
        }

        void Initialize()
        {
            Window.Instance.KeyEvent += OnKeyEvent;

            View root = new View
            {
                HeightResizePolicy = ResizePolicyType.FillToParent,
                WidthResizePolicy = ResizePolicyType.FillToParent,
                BackgroundColor = Color.White,
            };

            WebView webView = new WebView
            {
                Url = "http://localhost:5078",
                HeightResizePolicy = ResizePolicyType.FillToParent,
                WidthResizePolicy = ResizePolicyType.FillToParent,
            };

            root.Add(webView);

            Window.Instance.GetDefaultLayer().Add(root);
        }

        public void OnKeyEvent(object sender, Window.KeyEventArgs e)
        {
            if (e.Key.State == Key.StateType.Down && (e.Key.KeyPressedName == "XF86Back" || e.Key.KeyPressedName == "Escape"))
            {
                Exit();
            }
        }

        static void Main(string[] args)
        {
            var app = new Program();
            app.Run(args);
        }
    }

My web application is the standard boilerplate code generated by ASP.NET:

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

            // Add services to the container.
            builder.Services.AddControllersWithViews();

            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (!app.Environment.IsDevelopment())
            {
                app.UseExceptionHandler("/Home/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();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");

            app.Run();
        }
    }

It contains all the .js, .html, and .css files. I can run both the TizenApp solution and WebApp solution separately, but I want to know how can I combine these two solutions so that the TizenApp can access the WebApp—in fact, how could the TizenApp act as the web server that hosts the WebApp throughout its life?

Looked at HttpClient and HttpListeners, but I don't think they can handle complicated web applications that ASP.NET could offer, so I was wondering if there are any alternatives?

0

There are 0 best solutions below