ASP.NET 5 RC1 Project Differences - asp.net

I just created another test project in VS 2015 using ASP.NET 5 MVC 6. Last time I was using beta-7 of the runtime. This time however, I am using RC1.
project.json file for RC1 version:
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
}
project.json file for beta-7 version:
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
}
Kestrel is a mono platform and I have no idea why the default template would set this up as opposed to IIS or IIS Express? Can someone explain how to correctly configure IIS (preferable) and IIS Express for Web apps running on RC1? Although the RC1 site is running and showing in the IIS Express task bar, why the Kestrel config entry?
What are the steps to switch to full IIS and CoreCLR?

ASP.NET 5 ships with support for 3 different servers:
Microsoft.AspNet.Server.IIS
Microsoft.AspNet.Server.WebListener (WebListener)
Microsoft.AspNet.Server.Kestrel (Kestrel)
You can configure your application to be hosted by any or all of these servers by specifying commands in your project.json file.
When launching a server, you can provide it with some configuration options. This can be done directly using command line parameters, or a configuration file containing the settings can be specified. The Microsoft.AspNet.Hosting command supports parameters for the server to use (such as Kestrel or WebListener) as well as a server.urls configuration key, which should contain a semicolon-separated list of URL prefixes the server should handle.
The project.json file demonstrates how to pass the server.urls parameter directly:
"kestrel": "Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"
Alternately, a configuration file can be referenced, instead:
"kestrel": "Microsoft.AspNet.Hosting --config hosting.ini"
Then, hosting.ini can include the settings the server will use (including the server parameter, as well):
server=Kestrel
server.urls=http://localhost:5000
Reference and more detailed information here:
http://docs.asp.net/en/latest/fundamentals/servers.html
Also, the Configure() method in new Startup class allows specifying which handler to use and you can specify
app.UseIISPlatformHandler()
with appropriate parameters to use IIS hosting.
Your application is most likely running under IIS (express) hosting because you might have IIS or IIS Express selected in the "Run" option (in the toolbar at the top in Visual Studio). If you want to use Kestrel, change that to "web" and then it will pick what's specified in the project.json configuration under command->web.

Related

appSettings.json not read when launching .net core windows service

I follow the MicroSoft guide to build a window service.
The appSettings.json file is read when running from Visual studio or command line, but when the service dll is ran from the service manager it fails.
All variables that are populated from config remain empty.
The problem is that windows service manager set the default directory as c:\windows\system32.
How to read from installation path?
At service startup, set the working path to the installation path this way:
//program.cs
IHost host = Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(conf =>
{
conf.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
})
...

Access linux-hosted ASP.NET Core 2.x webapp (without nginx)

My ASP.NET Core 2.1 webapp works perfectly on my dev setup. Now I want to test it in production.
The production server is Ubuntu 18. I followed the instructions. I don't want to setup nginx yet, just do some quick tests, and the instructions say:
"Either configuration—with or without a reverse proxy server—is a valid and supported hosting configuration for ASP.NET Core 2.0 or later apps".
So I built and published my project: dotnet publish --configuration Release.
Then on the server:
install the dotnet runtime
copied files to server (/var/www/myapp)
opened ports: sudo uwf allow 5000/tcp 80/tcp
run dotnet MyApp.dll (also tried sudo dotnet MyApp.dll)
It runs without errors/warnings, and says it's listening on http://localhost:5000.
On my local machine I tried http://serveripaddress (and http://serveripaddress:5000) but get nothing ("can't connect"). I can access that server with ssh, sftp, etc - only http isn't working.
What am I doing wrong?
the host default bind is 127.0.0.1 , so you can only access the app locally. if you want to access it from Network, please add --urls parameter. for example :
for development, you can run:
dotnet run --urls http://0.0.0.0:5000
and for deployed project, you can run:
dotnet MyApp.dll --urls http://0.0.0.0:5000
The dotnet core sdk I use is version 2.1.400.
Found the problem. I needed to use:
ASPNETCORE_URLS="http://0.0.0.0:5000" sudo dotnet MyApp.dll
Then it logs Now listening on: http://0.0.0.0:5000. And I can access that from a remote client.

VSTS msdeploy.exe error: ERROR_USER_NOT_AUTHORIZED_FOR_CONTENTPATH

I'm trying to create a release definition inside VSTS to deploy my ASP.NET Core 2.0 app on my production server.
I'm using the MSDeployAllTheThings extension: https://marketplace.visualstudio.com/items?itemName=rschiefer.MSDeployAllTheThings
I'm able to deploy inside Visual Studio using the same configuration...
VSTS Config (not working)
VSTS Error
Visual Studio Config (working)
Do you guys have any ideas how to do that?
I had the same problem with deployment to smarterasp.net and was able to setup things for Web Deploy:
Your Dotnet Build task could create deployment package with necessary files like [YourProject].deploy.cmd, [YourProject].zip and etc. For this you could use next Arguments in your Build Task:
--configuration $(BuildConfiguration) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\"
Add "Batch script" task and set path to your [YourProject].deploy.cmd in Path field and also in your Arguments:
/y /m:$(SmarterAspNet.PublishUrl) -AllowUntrusted /u:$(SmarterAspNet.UserName) /p:$(SmarterAspNet.Password) /a:Basic "-setParam:name='IIS Web Application Name',value='$(SmarterAspNet.SiteName)'" -enableRule:AppOffline
With this two main DevOps tasks I was able to deploy my app to smarterasp.net
About MSDeployAllTheThings task: I removed it because it is not needed for me anymore
Not familiar with smarterasp.net. But this should be an issue with that site.
If you run the same msdeploy command from your local machine manually, you will get the same error message. We didn't see this error when use the same command to deploy to some other host instead of smarterasp.net. And if you add "-verbose" in the command, you will get a more detailed information which indicates that the command failed to adding the virtual path:
When you deploy your project from VS, it use the manifest file and source folder directly rather than "package" method. So you'd either contact smarterasp.net for help or use the same deploy method as Visual Studio or some other deploy method like FTP.

Dotnet Core publish to IIS from Mac

I want to publish my dotnet core app to IIS from mac. I use VS code for code writing and Dotnet Core 1.1 for publishing to local directory. (for example: bin/release/publish). There are compiled my files, ready to copy to IIS. On my IIS I currently have installed web deploy 3.6 and this is my VPS machine. Is there elegant way, how to copy files? The another way is using docker, but in this case I have the same problem. Generated docker file with docker publisher tool and I need to copy from mac os.
Thank you for your time.
From a terminal window navigate to the folder where your .csproj file is. From there run 'dotnet publish -c release'. A folder called publish will be created in bin/Release/netcoreappX.X. You can copy those files to the appropriate directory on your server. If you need help setting up IIS, follow the link below.
https://learn.microsoft.com/en-us/aspnet/core/publishing/iis
You can also run 'dotnet publish -h' to see all of the different arguments you can pass to the publish command.
Web Deploy (msdeploy.exe) seems to work in Mono, at least in WSL (Ubuntu 18.04). The tricky part is to extract the msi package somehow, which you can do easily on a Windows machine (you'll find the files in C:\Program Files\IIS\Microsoft Web Deploy V3).
Once you install Mono and obtain msdeploy.exe, just call the command, e.g.
mono msdeploy.exe -verb:sync -source:contentPath=/mnt/c/Data -dest:contentPath=test,ComputerName=https://example.com:8172/msdeploy.axd,UserName=WDeployAdmin,Password=PASSWORD,IncludeAcls=False,AuthType=Basic -enableRule:AppOffline -enableRule:DoNotDeleteRule -verbose -allowUntrusted:true
This lets you sync/copy the contents of /mnt/c/Data with the test web site in IIS on example.com with Web Deploy enabled.

How to run Microsoft.AspNet.Server.Kestrel webserver to different port for localhost machine

I have an MVC 5 project.
For debugging, I need to launch Microsoft.AspNet.Server.Kestrel web server on port 80.
But when I'm publishing this website to Azure, it does't work (IT requires to change port to 8000).
How to configure different ports in project.json for debug and release modes?
You could use a different command for debugging:
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"web-debug": "Microsoft.AspNet.Server.Kestrel --server.urls=http://localhost:8000"
}
Then launch web-debug to debug locally (in Visual Studio, you can change the default command in project properties).

Resources