F5 does not launch application until an endpoint is called - .net-6.0

Consider the following:
console application in netcoreapp2.1 that is set up to load some NuGet packages and place them in a folder within the project. Upon completion, application stops
After upgrading the application to net6.0, the NuGet pckages are only loaded after making an HTTP request to any endpoint in the app
More specifically, I hit F5 to launch the application in Debug mode:
netcoreapp2.1 does what it is supposed to, and then debug stops
net6.0 does not start application until HTTP request is sent from browser
the process name is different between the applications
Trying to find what could be causing this, I came across this post that lists an expected flow of actions when we hit F5:
VS will load all required symbols
Then, it will attach the debugger to a process
Then, it will launch the application
It seems like my net6.0 does not hit step 1 until I make a call to an endpoint, but I am not sure how to move forward, or what to look for.
I'm very new to development in general, and often can't find the proper terms to use when searching for a problem, so any advice you can give search-wise is appreciated!

After seeing this answer in another post, I realized I was debugging using the wrong profile. After selecting the project one (or using process {project name}.exe), the application behaved as expected.
launchSettings.json -> profiles
Before:
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
After:
"profiles": {
"Project Name": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"hotReloadEnabled": false
}
}

Related

What is the correct way add a protocol to the macOS info.plist using electron-builder?

I need to be able to launch my Electron app from the the browser (like sign in to Slack does). I know that I can add my protocol name to my Electron app using app.setAsDefaultProtocolClient(protocol[, path, args]) in Electron.
Then in electron-builder, I can use the package.json config build.mac with the extendInfo property to define "The extra entries for Info.plist". This however is the only instructions the docs give on how to use it.
What is the correct way add a protocol to the macOS info.plist using electron and electron-builder config build.mac.extendInfo and be able to use it as described?
(Posted a solution on behalf of the question author to move it to the answer space).
It now works with the following - I have added this to my Electron package.json:
"protocols": {
"name": "my-app",
"schemes": [
"my-app"
]
},
"mac": {
"target": "dmg",
"extendInfo": "my-app"
},
I have this in the electron.js:
app.setAsDefaultProtocolClient('my-app');
And this in my React browser client app code to launch the application from the browser:
document.location = 'my-app://open?url='
This question relates to how custom schemes are used to receive OAuth responses, as in my code sample which you can run locally, then use deep linking etc:
Code
Blog Post
Points of interest:
An interstitial web page returns control to the browser app - see this page
My package.json exposes the scheme for Electron deployment
This should give you something to compare against. Here is the key code:
INTERSTITIAL WEB PAGE INVOKING APP
window.addEventListener('DOMContentLoaded', function() {
var redirectUri = 'x-mycompany-desktopapp:/callback';
if (window.location.search) {
redirectUri += window.location.search;
}
document.getElementById('continueButton').onclick = function() {
window.location.href = redirectUri;
};
}
REGISTERING THE SCHEME
This gets picked up by Electron packager and included in platform specific binaries, resulting in OS specific registration:
"build": {
"protocols": {
"name": "finaldesktopapp",
"schemes": [
"x-mycompany-desktopapp"
]
}
},
RECEIVING NOTIFICATIONS
This enables the following code to work in the main side of the app, as specified in the main.ts file:
app.setAsDefaultProtocolClient(this._configuration.oauth.privateSchemeName);
Finally you register a callback that can parse the URL and take whatever is the appropriate action - completing a login in my case.
private _receiveNotificationInRunningInstance(privateSchemeUrl: string) {
}
The mechanics are a little tricky and the notification is received differently on macOS to Windows / Linux. See this source file and its comments which explain the details.

Authentication from Development to Release

I have a small web project to develop for a friend that will be incorporated into a small existing website using Visual Studio 2015.
A user has to be logged in, requiring a secure connection. I cannot use the existing website to authenticate with their SSL/Certificate during development because the URL will not be the same (or at least I don't know how).
Social media logins or traditional email/password logins can get involved to implement (new user, existing user, lost passwords, change passwords). I have only done it once before, so I would rather not have to change all of those settings from the development site to the existing site after it all gets working.
How do experienced people do this?
I would solve it using separate configuration files for each environment.
Each environment has specific configuration in its own file:
Each config file can have different security-concen configuration:
appsettings.Local.json
{
"TokenValidationConfig": {
"ValidAuthority": "https://localhost:8394",
"RequireHttpsMetadata": "false"
},
"HttpsConfig": {
"CertificateIdentifier": "Unnecessary for local env"
}
}
appsettings.Prod.json
{
"TokenValidationConfig": {
"ValidAuthority": "https://xxx.xxx.com"
},
"HttpsConfig": {
"CertificateIdentifier": "https://xxx.xxx.vault.azure.net/secrets/wildcard-xxx-xxx"
}
}
Current environment is specified in environment variable, and then is read on startup:
new WebHostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
var envName = hostingContext.HostingEnvironment.EnvironmentName;
config
.AddJsonFile(
path: "appsettings.json",
optional: false,
reloadOnChange: false)
.AddJsonFile(
path: $"appsettings.{envName}.json",
optional: false,
reloadOnChange: false);
Consider official documentation on the matter:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1#json-configuration-provider

How To Disable Https in Visual Studio 2017 Web Proj ASP.NET Core 2.0

I've created a default project in Visual Studio 2017 with ASP.NET Core 2.0. I've chosen the Web App with MVC and with Individual Use Auth. By default, it is coming up configured and working with https. I've tried disabling that by going into project properties and removing the user ssl and changing https to http but then I get either and IIS Express Connection error or a 404.
I've not see default https before. Where is that coming from and where can I disable it?
Update .Net 6
If you stumbled across this question, but are looking to disable SSL in .Net 6, follow these instructions:
Disable SSL redirection by removing app.UseHttpsRedirection();
(optional) define a default port to listen to with app.Run("http://localhost:5000"); If omitted, a random port will be assigned.
Original answer for .Net Core 2.0:
I've just created a default MVC app using net core 2.0.
To disable SSL, you need to do 2 steps. You can do this either by using the Visual Studio GUI, or by editing the launchsettings.json (further down)
go to your project properties
In the Debug category uncheck the SSL option
Copy the App Url over to the Start browser input
Et voila:
If you are not a fan of using the interface, you can alternatively edit the launchsettings.json file, by setting sslPort: 0 and "launchUrl": "http://localhost:13121/" (or where ever you want to launch the application)
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:13121/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "http://localhost:13121/",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"WebApplication1": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:13122/"
}
}
}
I was just having this same issue (ie. I needed a non-SSL URL to establish a working ngrok.com tunnel)
There's probably an alternative unsecured localhost URL defined.
I realize the question is to disable the secured one, but you probably don't need to. You probably already have an unsecured one defined.
Admittedly, I inherited this project so I'm not aware if a default project would be configured the same. My assumption is that there's an unsecured URL already available for you that you might be overlooking.
If I'm wrong this answer seems good (Ngrok errors '502 bad gateway'), but again I didn't need to try it.
Just look in the "Development Server" properties.
See my screenshot below:
Go to App Properties and uncheck "Enable SSL"
If the answer provided by #Marco didn't resolved the issue you can try this,
When you create new .net core mvc application there will be default meta tag generated in _Layout cshtml to upgrade the http request to https ( "http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"). When you deploy your application to server without http you may need to remove the below tags
http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"
Also comment the below line from Startup.cs file
app.UseHttpsRedirection();
It's most likely in your publish settings.
I had this issue and I simply went to the publish settings and discovered that after the build, the publish url contained https.

How to set start page in dotnet core web api?

I try to build a web application with dotnet core web api,but i do not know how to set index.html as start page which can be done with dotnet framework web api easily. And i tried to use app.UseDefaultFiles();app.UseStaticFiles(); to solve this problem, however, it did not work.
In Properties/launchSettings.json you can define the launchUrl
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "<your relative URL here>",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
Step 1
app.UseDefaultFiles();
app.UseStaticFiles();
Step 2
Create a folder called "wwwroot". put a file called index.html
Step 3 (optional)
If you are the using the auto generated template, you can remove make the launchUrl blank like this
"launchUrl": "",
Otherwise, you will have to manually keep going to the landing page every time during localhost running.
This is the correct way. But always use UseDefaultFiles() before UseStaticFiles
Otherwise it won't work.
For reference: Core fundamentals of Static Files
If you are using a static file as the default page, the following code can help you.
app.UseDefaultFiles(new DefaultFilesOptions { DefaultFileNames = new
List<string> { "index.html" } });
If you are using the MVC view, just add the routing role.
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}");
});
For Asp.Net Core 2.0/2.1/2.2 just right click on Project → Properties → Debug
and next to Launch Browser checkbox set path to the startup page you want.
Your index.html file must be in the wwwroot folder
wwwroot / index.html
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files
You can set any file in any folder under the wwwroot as defaut file by using options.DefaultFileNames.Add in startup.cs .
For example to use myfile.html in wwwroot/folder1/folder2/ myfile.html, you will add this in Startup.cs
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("folder1/folder2/ myfile.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
But some time it may not work. For example
I created project File menu > New > Project , then selected .NET Core > ASP.NET Core Web Application and selected Web Api as project template.
F5 always open page api/values, even though I added index.html in wwwroot folder and added following in startup.cs
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("mypage.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
Then I opened project properties page and deleted the value in Debug/Launch browser box (which was set to api/values)
Now setting of startup page is working and mypage.html is startup page. Note that this page should be in wwwroot folder as you have opted to use static files.
For dotnet core web api 3.1, on launchSettings.json file set "launchUrl": "swagger/index.html",
For Asp.Net Core 2.2 right click on Project → Properties → Debug and next to Launch Browser checkbox set path to the startup page you want.
Project VS
If Index.html is in project root, it will be send by default.

How to create a desktop app version of a website using NW.js?

I've been using Fluid App (OS X) in the past to create standalone desktop apps of specific web apps I want separated from the browser, have their own dock icon, and not have any of the regular browser fluff (toolbar, address bar, etc.). Fluid app, though, has been neglected for a long time and certain newer web apps (e.g. Inbox from Google) completely fail to load in it.
So I'm looking for a simple way to create a desktop app that will have a single window loading a single website, and I think that NW.js would be ideal for that.
What should be the configuration process for building such a simple desktop app for just a webview for a given URL, using NW.js?
If you simply want to open a single webpage in a NW.js program, it is exceptionally easy.
First make sure you read: https://github.com/nwjs/nw.js/wiki/How-to-run-apps
Especially the MacOS section.
Make a directory your_project/
create a file in your_project/package.json
Then configure package.json:
{
"main": "https://github.com",
"name": "github app",
"description": "Github demo app",
"version": "0.1.0",
"keywords": [ "demo", "node-webkit" ],
"nodejs": false,
"window": {
"title": "Github",
"icon": "logo.png",
"toolbar": false,
"frame": true,
"width": 1024,
"height": 768,
"position": "mouse",
"min_width": 400,
"min_height": 200
},
"webkit": {
"plugin": true
}
}
You can run nwjs from the nwjs.app/Contents/MacOS/nwjs path_to_your_project
Note the "nodejs": false option this disables the nodeapi for the application, if you end up needing nodejs in part of your application make sure what whatever webview you use had nodejs disabled as this is a major security flaw, do your research - do it right.
Also note that nothing is preventing the user to access content from other domains in the above example.
You will eventually want to look at packaging your application, which is also quite simple: https://github.com/nwjs/nw.js/wiki/how-to-package-and-distribute-your-apps

Resources