Last week, it's Microsoft Build week, and hope you have enjoyed it.
There were some nice announcements and one of my favorites out of them all is this nice feature that got released with Visual Studio 2022 17.3.0 Preview 1.1. That's introducing the private preview of port tunneling in Visual Studio for ASP.NET Core projects.
With this, I can run my Web Application locally and the URL it's running is public and can be accessed from outside of my local environment. With most of us working from home, I am finding this very helpful. I can do things like,
- Share the public URL with a colleague to test out the application.
- If it's a Frontend Web Application, access the URL from my mobile, and see how it's behaving.
- I don't have to deploy the application to test a Webhook with a third party etc
In order to use this feature, there are a couple of things you need to do
first.
The first thing is obviously you need to download and install the latest
preview of Visual Studio 2022. And that's Visual Studio 2022 17.3.0 Preview 1.1.
Next, you need to sign up for the private preview program of port
tunneling in Visual Studio. Otherwise, you are going to get an error like
below when you are going to try it.
You can do it by filling out the form here:
https://aka.ms/tunnels-signup. Something to note here is, it's going to take some time for access to be
granted into the private program and at this time individual users will not be
considered, only organizations with tenant IDs.
After signing up with the preview program, log in to Visual Studio with the
email address you have used. Then under Tools ->
Options -> Environment -> Preview Features, check
Enable port tunneling for Web Applications.
Finally, create a new ASP.NET Core Web Application, and once the project is
created, update the launchSettings.json as below.
launchSettings.json
{ "$schema": "https://json.schemastore.org/launchsettings.json", "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:4367", "sslPort": 44305 } }, "profiles": { "WebApplication1": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "launchUrl": "swagger", "applicationUrl": "https://localhost:7015;http://localhost:5015", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "createTunnel": true, "tunnelAuthentication": "public", }, "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } } } }
The only change I have done here is I have added the below properties under the profile I am using to run the Application.
- "createTunnel": true
- "tunnelAuthentication": "public"
And that's it. Now you can launch the application.
Note: Tunnels are created with private access by default, meaning that only
the user who created the tunnel can access it after signing in. You can
control this access by adding the "tunnelAuthentication" property. Valid values
include,
- private - only the user who created the tunnel can access it after signing in.
- org - only users in the organization can access it after signing in.
- public - the tunnel is accessible by anyone and no sign-in is needed.
Hope this helps.
Happy Coding.
Regards,
Jaliya
No comments:
Post a Comment