# Local Application

{% embed url="<https://youtu.be/in4_EmGuvOQ>" %}
Wisej.NET Hybrid Offline Application
{% endembed %}

## Samples

{% embed url="<https://github.com/iceteagroup/wisej-hybrid-examples>" %}

## Configuration

When creating a new Hybrid Client application, an offline application can be specified with the **UseWisejOffline()** extension method.

{% code title="Startup.cs" %}

```csharp
public static MauiApp Main()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()

		 // Uncomment and replace with Offline startup Type to use embedded web server.
		 .UseWisejOffline<OfflineStartup>()

		// Uncomment when registering AppBuilderExtenders as part of a separate class library.
		// .UseWisejExtenders()

		.UseWisejHybrid((config) =>
		{
			// Uncomment to provide an offline fallback timeout.
			// config.OfflineTimeout = 5000;

			// Provide the startup URL for the Hybrid WebView.
			config.StartupUrl = "http://localhost:5000";
		});

	return builder.Build();
}
```

{% endcode %}

In the example above the client application registers an offline app, **OfflineStartup**, which runs an embedded web server that serves the Wisej.NET application:

{% code title="OfflineStartup.cs" %}

```csharp
public class OfflineStartup
{
	public static string Main(CancellationToken token, object[] args)
	{
		var url = "http://localhost:5000";
		var server = new WebServer(url);
		server.WithWisej();
		server.WithStaticFolder("/", Path.GetDirectoryName(typeof(OfflineStartup).Assembly.Location), true);

		new Thread(() => server.RunAsync(token).Wait()).Start();

		return url;
	}
}
```

{% endcode %}

{% hint style="warning" %}
The default **OfflineStartup** file can be found within the **Wisej.NET Hybrid Offline Application** project template in Visual Studio.
{% endhint %}

{% embed url="<https://github.com/unosquare/embedio>" %}
EmbedIO Source Code
{% endembed %}

## Switching Offline & Online Applications

It is possible to switch between the offline (disconnected) application and online (connected) application with one few line of code:

At any point in time, simply use **Application.Navigate("url", "target")** to switch between URLs.

For example, if an offline application was registered on port 5000, but you're currently connected to an "online" application, you can use the following line of code anywhere in your Wisej.NET application to switch to the offline version:

```csharp
Application.Navigate("http://localhost:5000");
```

#### Offline Fallback

If you would like to switch to the offline version of an application when the network gets disconnected, configure the **OfflineTimeout** member inside of the client app's Startup.cs file:

```csharp
public static MauiApp Main()
{
	var builder = MauiApp.CreateBuilder();
	builder
		.UseMauiApp<App>()

		// Uncomment and replace with Offline startup Type to use embedded web server.
		.UseWisejOffline<OfflineStartup>()

		.UseWisejHybrid((config) =>
		{
			// Uncomment to provide an offline fallback timeout.
			config.OfflineTimeout = 5000;

			// Provide the startup URL for the Hybrid WebView.
			config.StartupUrl = "http://localhost:5000";
		});

	return builder.Build();
}
```

The line `config.OfflineTimeout = 5000;` in the example above specifies that when the user is no longer connected to a network, the application should automatically switch from the "online" version to the "offline" version of the application.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/hybrid/development/local-application.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
