Using ASP.NET in a Content
By default, ASP.NET does not allow applications to be accessed remotely. This means that the in-project web browser will not be able to access the application, as it is technically running outside of the sandbox environment.
To address this, add a UseUrls statement, as shown below:
1
public static IWebHost BuildWebHost(string[] args) =>
2
WebHost.CreateDefaultBuilder(args)
3
.UseUrls("http://*:5000")
4
.UseStartup<Startup>()
5
.Build();
6
}
Copied!
Some projects use a different port such as 5001. Replace 5000 with the port your application uses everywhere that 5000 is used in this guide.
If your application includes any forms, you will need to add the following line of code in the Startup.cs class's ConfigureServices method before calling AddRazorPages or AddMvc:
1
services.AddAntiforgery(o => o.SuppressXFrameOptionsHeader = true);
Copied!
Without this line, anytime an Antiforgery token is generated (most forms generate this token) the X-Frame-Options header is automatically added, which can cause "connection refused" errors in the Web Browser tab.
Set the applicationURL to "http://0.0.0.0:5000" in Properties\Launchsettings.json.

Content Settings

To get the ASP.NET Core app to work, you’ll need to change a few settings. Under Tabs Enabled, check “Enable Web Browser”.
With that done, go to the now visible Web Browser Settings. There, change the Starting Browser URL to {{localhost:5000}}.
Under Settings, add the following in the startup script to enable SQL Server:
1
sudo systemctl enable mssql-server
2
sudo systemctl start mssql-server
Copied!

EF Core and database generation

Change the connection string in your application as follows. Of course, the database name you can choose yourself:
1
"ConnectionStrings": {
2
"DefaultConnection": "Server=.;Database=BethanysPieShop;User Id=sa;[email protected]"
3
},
Copied!
If you are using Entity Framework Core and want to use scaffolding to restore your database, you should first now install the EF Core tools by running the following command in a Terminal tab:
1
dotnet tool install --global dotnet-ef
Copied!
Now, navigate to the folder where your .csproj lives and there, run:
1
dotnet build
Copied!
After successful build, run the following to restore your database:
1
dotnet ef database update
Copied!
Your migrations will now be executed while generating the database.

Running the Application

You can then use dotnet run to start your application. Open a browser tab and navigate to http://localhost:5000. You should now see your site!
Tip: Projects run on Linux so folder/file paths are case sensitive. Therefore “contents/site.css” is not the same as “Contents/site.css”!