{"id":238206,"date":"2022-05-25T08:04:16","date_gmt":"2022-05-25T15:04:16","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/visualstudio\/?p=238206"},"modified":"2022-11-01T09:22:22","modified_gmt":"2022-11-01T16:22:22","slug":"introducing-private-preview-port-tunneling-visual-studio-for-asp-net-core-projects","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/introducing-private-preview-port-tunneling-visual-studio-for-asp-net-core-projects\/","title":{"rendered":"Introducing the private preview of port tunneling in Visual Studio for ASP.NET Core projects"},"content":{"rendered":"<p>In Visual Studio 2022 17.3 Preview 1.1 we added support to port tunneling (forwarding) to your ASP.NET Core web projects. Port tunneling enables connections between machines that cannot directly connect to each other. Port tunneling is also referred to as port forwarding, or web tunneling. Some cases where you may want to use port tunneling while developing an ASP.NET Core app include:<\/p>\n<ul>\n<li><a href=\"https:\/\/docs.microsoft.com\/en-us\/connectors\/custom-connectors\/port-tunneling\">Developing an API that is consumed by Power Platform<\/a>.<\/li>\n<li>Developing a web hook for an external service.<\/li>\n<li>Testing a web app on an external device.<\/li>\n<\/ul>\n<p>These are just a few examples of when you may want to use port tunneling with your web projects. This feature depends on a private preview which you must sign up for.<\/p>\n<p>To get started follow these steps.<\/p>\n<ol>\n<li>Sign up for the private preview of port tunneling in Visual Studio.<\/li>\n<li>Download the 17.3 Preview 1.1 Visual Studio update.<\/li>\n<li>Enable the preview feature in Visual Studio.<\/li>\n<li>Configure your project.<\/li>\n<\/ol>\n<h2>1: Sign up for the private preview of port tunneling in Visual Studio<\/h2>\n<p>To get started with the, sign up for the private preview at the link below. You should sign in with the same account that you are using in Visual Studio. Port tunneling will not work without signing up for this preview.<\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/aka.ms\/tunnels-signup\" target=\"_blank\">https:\/\/aka.ms\/tunnels-signup<\/a><\/div><\/p>\n<p>After signing up, download the Visual Studio preview and enable the feature in Visual Studio.<\/p>\n<h2>2: Download the latest preview Visual Studio update<\/h2>\n<p>We added support for this preview feature in Visual Studio 2022 17.3 Preview 1.1, but you should use the latest current preview available. You can download that at the link below.<\/p>\n<p><div  class=\"d-flex justify-content-center\"><a class=\"cta_button_link btn-primary mb-24\" href=\"https:\/\/visualstudio.microsoft.com\/vs\/preview\/ \" target=\"_blank\">https:\/\/visualstudio.microsoft.com\/vs\/preview\/ <\/a><\/div><\/p>\n<h2>3: Enable the preview in Visual Studio<\/h2>\n<p>In Visual Studio go to <em>Tool &gt; Options &gt; Preview Features<\/em> and check the <strong><em>Enable port tunneling for Web Applications<\/em><\/strong> option.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/01-preview-features-min.png\"><img decoding=\"async\" class=\"size-full wp-image-238207 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/01-preview-features-min.png\" alt=\"vs preview features port forwarding\" width=\"776\" height=\"666\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/01-preview-features-min.png 776w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/01-preview-features-min-300x257.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/01-preview-features-min-768x659.png 768w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/a><\/p>\n<h2>4: Configure your project<\/h2>\n<p>When developing ASP.NET Core projects in Visual Studio, the settings to launch your application are stored in the file at <em>Properties\/launchSettings.json<\/em>. This file contains one, or more, launch profiles for your web app. In order to enable the tunnel to be created, or connected, when you run your app, add the property \u201ccreateTunnel\u201d: true in the launch profile. For example, below is a full <em>launchSettings.json<\/em> file for an ASP.NET Core web project.<\/p>\n<pre class=\"prettyprint\">{\r\n  \"iisSettings\": {\r\n    \"windowsAuthentication\": false,\r\n    \"anonymousAuthentication\": true,\r\n    \"iisExpress\": {\r\n      \"applicationUrl\": \"http:\/\/localhost:28981\",\r\n      \"sslPort\": 44342\r\n    }\r\n  },\r\n  \"profiles\": {\r\n    \"MyWebApp\": {\r\n      \"commandName\": \"Project\",\r\n      \"dotnetRunMessages\": true,\r\n      \"launchBrowser\": true,\r\n      \"applicationUrl\": \"https:\/\/localhost:7130;http:\/\/localhost:5130\",\r\n      \"environmentVariables\": {\r\n        \"ASPNETCORE_ENVIRONMENT\": \"Development\"\r\n      },\r\n      <strong>\"createTunnel\": true, \r\n      \"tunnelAuthentication\": public<\/strong>\r\n    },\r\n    \"IIS Express\": {\r\n      \"commandName\": \"IISExpress\",\r\n      \"launchBrowser\": true,\r\n      \"environmentVariables\": {\r\n        \"ASPNETCORE_ENVIRONMENT\": \"Development\"\r\n      }\r\n    }\r\n  }\r\n}<\/pre>\n<p>The property that needs to be added is in bold above. When you run, or debug, your application in Visual Studio. Instead of launching the localhost URL, the tunnel URL will be launched, which will then connect to the localhost endpoint. Take a look at the animation below.<\/p>\n<p><strong>Note: when this feature was originally implemented the access was set to public by default. In more recent updates, we default to private access, where only the signed in user has access to that tunnel. You can control the access with the property &#8220;<span style=\"font-size: 1rem;\">tunnelAuthentication&#8221;, which can be set to &#8220;private&#8221;, &#8220;org&#8221; or &#8220;public&#8221;. For org access, the user accessing that tunnel must have access to the organization in which the tunnel was created.<\/span><\/strong><\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/02-run-in-vs-with-tunnel-min.gif\"><img decoding=\"async\" class=\"size-full wp-image-238208 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/02-run-in-vs-with-tunnel-min.gif\" alt=\"run in vs with tunnel\" width=\"1920\" height=\"1080\" \/><\/a><\/p>\n<p>When the web app is launched, you can see that the browser is not navigating to the localhost URL, but instead using the public tunnel URL. This URL can be accessed outside of your local environment. You could share the public URL with a friend or colleague to test out the application. If you wanted to test your web app on an external device like a phone or tablet, you can navigate to the URL on the device. To simplify this, you can generate a QR code to the URL in the Edge browser. To create the QR code in Edge, click on the URL bar and the QR code button should appear. Click on that to generate, and view, the QR code.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min.png\"><img decoding=\"async\" class=\"size-full wp-image-238209 aligncenter\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min.png\" alt=\"qr code\" width=\"1389\" height=\"809\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min.png 1389w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min-300x175.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min-1024x596.png 1024w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/03-qr-code-min-768x447.png 768w\" sizes=\"(max-width: 1389px) 100vw, 1389px\" \/><\/a><\/p>\n<p>You can scan this QR code with your phone, or tablet, to navigate to the URL.<\/p>\n<h2>Changes in Visual Studio 2022 17.4 Preview 3<\/h2>\n<p>In the 17.4 Preview 3 release of Visual Studio 2022, several changes have been made. Those changes are summarized below.<\/p>\n<h3>The property names used in launchSettings.json have changed<\/h3>\n<table>\n<tbody>\n<tr>\n<td width=\"312\">Old property name<\/td>\n<td width=\"312\">New property name<\/td>\n<\/tr>\n<tr>\n<td width=\"312\">createTunnel<\/td>\n<td width=\"312\">devTunnelEnabled<\/td>\n<\/tr>\n<tr>\n<td width=\"312\">tunnelAuthentication<\/td>\n<td width=\"312\">devTunnelAccess<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h3>Preview Features name has changed<\/h3>\n<p>The name of the tab in Preview Features was initially set to \u201cEnable port tunneling for web applications\u201d and now has been changed to \u201cEnable dev tunnels for web applications\u201d.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/05-tools-options-dev-tunnels.png\"><img decoding=\"async\" class=\"alignnone wp-image-239836 size-full\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/05-tools-options-dev-tunnels.png\" alt=\"preview features enable dev tunnels\" width=\"915\" height=\"640\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/05-tools-options-dev-tunnels.png 915w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/05-tools-options-dev-tunnels-300x210.png 300w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/05-tools-options-dev-tunnels-768x537.png 768w\" sizes=\"(max-width: 915px) 100vw, 915px\" \/><\/a><\/p>\n<h3>Supported account types<\/h3>\n<p>In 17.4 Preview 3 we have added support for both MSA and GitHub accounts when using dev tunnels. In the <a href=\"http:\/\/aka.ms\/tunnels-signup\">signup form<\/a>, you\u2019ll now see an option to input your GitHub username.<\/p>\n<h3>Environment variable to get the dev tunnel URL<\/h3>\n<p>When a project is started with tunnel support, an environment variable is added to the process VS_TUNNEL_URL which can be used to get the tunnel URL which is being used. In a multi-project start scenario, when a project is started with a tunnel, projects that start after that project will get an additional environment variable named VS_TUNNEL_URL_{PROJECTNAME}, where {PROJECTNAME} is the name of the project that started earlier with a tunnel.<\/p>\n<p>For example, consider the following. You have a solution with a web API project as well as a Web project. The multi-project start is configured to start the API project first, and then the web project, and they both have tunnel enabled. In the API project it will get the VS_TUNNEL_URL for its own tunnel. Let\u2019s say that the API project is named \u201cMyApi\u201d and the web project is named \u201cMyWeb\u201d. When the web project is started it will have an environment variable named VS_TUNNEL_URL which has the URL for its own tunnel. It will also have an additional environment variable named VS_TUNNEL_URL_MyApi, which is the tunnel URL for the API project which launched before the web project.<\/p>\n<h2>What to do if you run into issues?<\/h2>\n<p>This is an early preview, so you may run into some issues when using this feature. The best method to report issues is using the built in <a href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2022\">Report a Problem<\/a> support in Visual Studio. You can also leave a comment here or reach out to Sayed on Twitter at <a href=\"https:\/\/twitter.com\/sayedihashimi\">@SayedIHashimi<\/a>.<\/p>\n<h2>Known Issues<\/h2>\n<ul>\n<li><del>GitHub.com accounts are not currently supported.<\/del>\n<ul>\n<li><del>We will add support for GitHub.com accounts in a future update.<\/del><\/li>\n<\/ul>\n<\/li>\n<li>Multiple accounts in Visual Studio\n<ul>\n<li>If you are signed in with multiple Azure accounts in Visual Studio, the tunnel will be created with the first Azure account detected.<\/li>\n<li>Later we will add the ability to select a specific account to create the tunnel with.<\/li>\n<li>If you see a dialog with the following message, the account that is signed into Visual Studio doesn\u2019t have access to create the tunnel. Ensure that you are signed in with an Azure account in Visual Studio.\n<ul>\n<li><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/04-user-acct-error-min.png\"><img decoding=\"async\" class=\"alignnone size-full wp-image-238210\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/04-user-acct-error-min.png\" alt=\"user acct error\" width=\"413\" height=\"211\" srcset=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/04-user-acct-error-min.png 413w, https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2022\/05\/04-user-acct-error-min-300x153.png 300w\" sizes=\"(max-width: 413px) 100vw, 413px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>Tunnel authentication\n<ul>\n<li>Currently all tunnels are created with anonymous authentication enabled.<\/li>\n<li>We are planning to make all new tunnels secure by default in a future update, with the ability to configure the auth settings.<\/li>\n<\/ul>\n<\/li>\n<li>302 Error\n<ul>\n<li>When accessing the tunnel URL the request may be redirected, if the client is not following redirects you may encounter a 302 error.<\/li>\n<li>When you get a 302 error you can modify the global URL to point to the specific data center where the tunnel exists. For example if your global URL is https:\/\/vstunnel123456.rel.tunnels.api.visualstudio.com, instead use https:\/\/vstunnel123456.use.rel.tunnels.api.visualstudio.com.<\/li>\n<li>We have seen 302 errors when configuring GitHub web hooks. We are going to work with GitHub to resolve this issue.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Wrap Up<\/h2>\n<p>In this post we introduced the new web tunneling feature for ASP.NET Core apps in Visual Studio, and what steps you should take to try it out. This is just an early preview; we will continue to improve this experience so that we can release this in a non-preview build. Please try it out and let us know how it\u2019s working for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Visual Studio 2022 17.3 Preview 1.1 we added support to port tunneling (forwarding) to your ASP.NET Core web projects. Port tunneling enables connections between machines that cannot directly connect to each other. Port tunneling is also referred to as port forwarding, or web tunneling. Some cases where you may want to use port tunneling [&hellip;]<\/p>\n","protected":false},"author":357,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[],"class_list":["post-238206","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio"],"acf":[],"blog_post_summary":"<p>In Visual Studio 2022 17.3 Preview 1.1 we added support to port tunneling (forwarding) to your ASP.NET Core web projects. Port tunneling enables connections between machines that cannot directly connect to each other. Port tunneling is also referred to as port forwarding, or web tunneling. Some cases where you may want to use port tunneling [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/238206","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/357"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=238206"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/238206\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=238206"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=238206"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=238206"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}