Normally I have hosted my Asp.Net Application from Visual Studio using IISExpress profile by just starting debug.
How can I host the same Asp.Net project from the command Prompt, so that the hosted application was active and use appsettings.Development.json configuration?
You can chop and hack, and suffer great pains. You CAN get IIS Express to work, but this begs the quesiton why suffer so much?
Just get a copy of IIS and install it. You get the FULL configuration, and that is a FANTASTIC learning experience if you actually THEN have to setup a running web server.
Really, but really, do yourself a BIG nice favor:
Just install the full version of IIS - that's what it is for, and messing around and playing with IIS express while possible? it just a lot of pain and hassle, and the WHOLE HUGE provided GUI you get/have with the full edition of IIS allows you not only with ease to "configure" IIS, but also get a good feel l for setup and running IIS.
I kind of wish like sql server vs sql server express? You can download the SSMS (sql server management studio and use SSMS for both SQL server, and SQL server express. Then comes the day you have to do some work on a server will SQL server, and you not skip a beat).
The same applies to IIS express. (but, the IIS management system, tools and GUI to manage IIS is not a separate download. I would simple install IIS on that computer if you want to run/test/have/enjoy a running web server. You can as noted, mess around with IIS Express, and mess around with config files, but really, it not worth the time as compared to installing IIS full edition.
Save world poverty, save your suffering, save your time, and invest a bit of time to use IIS, and you not only find overall it less pain, but now will have learned and adopted a new skill set, and will become comfortable with running IIS as a result.
Visual Studio uses launchSettings.json file which allows you to specify different launch profiles for your app: IIS Express, Project, Docker, etc.
You can select which profile to use in the Visual Studio menu just near the start debug button:
For each profile, you can specify various startup settings including environment variables:
{
"profiles": {
"EnvironmentsSample": {
"commandName": "Project", // launches Kestrel web server
"launchBrowser": false,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" // specifies environment
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:80"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
If you want to start the application manually from the command prompt:
dotnet run --environment Development
By default, ASP.NET Core reads configuration from appsettings.{environment}.json file. So appsettings.Development.json file will be used.
Related
This question already has answers here:
What is Kestrel (vs IIS / Express)
(4 answers)
Closed 1 year ago.
Actually I understand that IIS Express is lightweight development server. From the other side "dotnet run" runs the application as a console application and binds it to random port.
But what is the actual difference? I can launch big enterprise application by IIS Express and by "dotnet run" and both cases work perfectly.
Till now all the difference I see is that IIS Express adds icon to the taskbar and dotnet run allows to see console output. But those are minor differences. It should be some global ones why IIS Express is so widespread nowadays.
Some structurization can be found here: ASP.NET Core launch settings: IIS Express, IIS, Project, Executable. But it still doesn't explain the difference.
dotnet run will use the embedded Kestrel server. IIS Express will use IIS Express as a reverse proxy which calls Kestrel behind the scenes. In either case a server is hosting your app.
You can toggle your local server choice by adjusting the run configuration. IIS Express will use...IIS Express. But if you instead select the project (in the case of the screenshot, it's titled weatherapi) it will use Kestrel instead. You'll see a command prompt pop up, showing some basic configuration data (assuming you haven't changed the default logging output). The first time it's run, you may have to accept/install the localhost TLS certificate, so that you don't run into TLS errors.
One way of confirming which process you are using, is to call get-process in powershell, along with either iisexpress or {nameOfProject}
More info from the docs
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/servers/?view=aspnetcore-3.1&tabs=windows
I'm trying to run ASP.NET Core (.NET 4.6.1) application as self hosting by means of weblistener
I've add a command:
"commands": {
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"
},
and necessary dependencies in project.json
When I start my application via Visual Studio it's works fine
src\ProjectName\bin\Release\net461\win7-x64\ProjectName.exe
ProjectName.exe starts as web server with Hosting environment: Development
But when I run it by hand ProjectName.exe runs with Hosting environment: Production and it's not working properly.
First of all I want find way to run application by hand with Development environment
In VS I have this option:
When you start the application Visual Studio will automatically set the environment variables for you (based on settings from launchSettings.json in the properties folder).
When you run from commandline or double-click, you need to set the environment variable yourself using setx ASPNETCORE_ENVIRONMENT "Development" (Commandline) or $Env:ASPNETCORE_ENVIRONMENT = "Development" (Powershell).
I have just upgraded an app to RC2 and am testing all the hosting scenarios. I'm having trouble figuring out the best practice of how to setup the configuration of each scenario that they would all work.
Here are the scenarios:
1. Local debugging with WebListener (we need Windows Authentication)
2. Local debugging with Kestrel
3. Local debugging with IIS Express (+ Kestrel)
4. Published to IIS
I'm not sure if we need all these, but you know... developers and their preferences :)
So, when you publish the app to IIS, I've set up IIS application physical path to wwwroot-folder. The appsettings.json file is outside the wwwroot so I can load the configuration file using
new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), #"..\"))
This works fine. I have also setup the local self-hosted Kestrel and WebListener working directory to wwwroot so that the same logic applies there.
launchsettings.json
"workingDirectory": "wwwroot",
The problem is now with IIS Express. With IIS Express the current directory is the application root (same where appsettings.json is) so with the current setup, it cannot find the settings file. It seems that I cannot set a working directory for IIS Express(?) and this lead me to think that what is the preferred way to setup this that it would work in all of the mentioned scenarios?
I'm going to publish my Application in my Local IIS .But I have some Question before i Publish.
The Question is
If I host my application can I access my Application any system
in my local area Network?
Can I run the application
with out opening visual studio and run through visual Studio?
IIS : Internet Information Services
Yes if you deploy application,for sure you can access within your network.
Yes, If successfully deployed there is no need to open visual studio to run your application , as it is deployed already
How can I make Web Application project a standalone desktop application with IIS Express and SQL Server Express?
With "standalone" I mean clicking on an exe-file start my application (e.g. start.aspx in my browser). The whole application consists of lots of aspx-files which run in a browser.
NOW: I have my Web Application project running fine when pressing F5 in Visual Studio 2010.
MY AIM: I want to start this project on a local machine just as easy as it is in Visual Studio, but how could I do so?
You're misunderstanding what happens when you press F5 in Visual Studio.
When you press F5, and if you're using the Visual Studio Development Server instead of IIS, that server is started up, and can serve requests for your application that come in on localhost. In any case, Visual Studio next starts your default browser and tells it to browse to your web application. The only application being launched on the desktop is your browser.
When your application is ready for other users to use, you will need to deploy it to a web server. Once it is deployed to the web server, users will be able to open their browser and browse to your application.
There is no simple way to package up a web server, database server, and your web application into a single .exe that a user can double-click.
i recommend you look into this product
http://ultidev.com/products/UWS-Cassini-Pro/Default.aspx
You'll need to use SQL CE, which has a number of limitations, such as the inability to auto-increment identity type columns.
Why would you use IIS for a stand-alone desktop application? A web application is for the web. If you want desktop that look into WinForms of WPF. I doubt you will find any tools to do the conversion for you so you will have to make it a manual process. Just hope you have a well structured web app.
Unless of course, you mean to just access a local web application from your local machine IIS installation? If so, then just set up IIS like you would do on a server, assign yourself a port to the localhost to access the web application and then create a nice desktop shortcut that links to the correct URL