Last active
July 2, 2025 20:20
-
-
Save readingdancer/b3604395b2f713305e8a919144c3237c to your computer and use it in GitHub Desktop.
Add clickable Umbraco URL to terminal output when running locally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Add this to your program.cs file. | |
| // Output the Umbraco URL for easy access (only when running on localhost) | |
| app.Lifetime.ApplicationStarted.Register(() => | |
| { | |
| var configuration = app.Services.GetRequiredService<IConfiguration>(); | |
| var urls = configuration["ASPNETCORE_URLS"] ?? configuration["urls"]; | |
| // Check if we have localhost URLs or fallback to checking app.Urls | |
| var allUrls = new List<string>(); | |
| if (!string.IsNullOrEmpty(urls)) | |
| { | |
| allUrls.AddRange(urls.Split(';')); | |
| } | |
| allUrls.AddRange(app.Urls); | |
| var localhostUrl = allUrls.FirstOrDefault(url => url.Contains("localhost")); | |
| if (localhostUrl != null) | |
| { | |
| var umbracoUrl = $"{localhostUrl}/umbraco"; | |
| var logger = app.Services.GetRequiredService<ILogger<Program>>(); | |
| logger.LogInformation("Umbraco is running at: {UmbracoUrl}", umbracoUrl); | |
| Console.WriteLine($"Umbraco is running at: {umbracoUrl}"); | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you run your Umbraco site using
dotnet runyou will then get the following output in the terminal window that you can then easily click on to open Umbraco :)