I have a problem in running an asp.net core website on remote server.
I want to use kestrel with IIS ,and published it in visual studio 2017
It's my program.cs:
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://example.com")
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
At the remote server when I double click on myWebAppName.exe the kestrel run and very fast closed
What i must do?
pleas, help me
First of all: you don't need to click on app .exe file if you want to host in IIS. Doing this you run it as a standalone application. Instead you should create a IIS Website.
Configuration via code is only one of steps. You need also configure IIS to host your app. Follow this Set up a hosting environment for ASP.NET Core on Windows with IIS, and deploy to it official documentation to setup everything right.
Note: some steps are different for varied ASP.NET Core versions.
It seems that some unhandled exception is thrown ("app closed very fast"). Open command line (cmd.exe), navigate to your app folder and run .exe from command line - it will not close and you'll see error message.
After you fix bugs (and your app will run on server, not close) - read Set up a hosting environment for ASP.NET Core on Windows with IIS, and deploy to it to know how properly run your app under/behind IIS. In short: IIS will run your .exe itself (when website starts), there is no need to start it manually.
Related
I am new to .Net core environment and facing issue while deploying application into IIS.
After publishing code and deploying into IIS server(Version 7), I am able to start application from Kestrel by going into directory where application hosted and running below command.
c:\inetpub\demoapp\dotnet "My App.dll"
By running above command, Kestrel is running on http://localhost:5000 and I am able to browse from browser. I am using latest .Net Core version 2.2.
But when I am trying to execute URL from IIS hosted application, I am getting below error.
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
Below is the event log from windows application log.
Application '/LM/W3SVC/49/ROOT/demoapp' with physical root 'C:\inetpub\demoapp\' failed to start process with commandline 'dotnet .\MyApp Web.dll' with multiple retries. The last try of listening port is '2405'. See previous warnings for details.
Anyone having idea how to resolve it?
In my case, It was win-64 architect issue.
You can change or switch architect from win-64 to win-86 then publish and don't forget to change Enable 32-bit Applications in IIS manager:
Right-click on the Application Pool and select “Advanced Settings…”
or select the same from the Actions pane after selecting the
Application pool.
Change the “Enable 32-bit Applications” to True (if you want the
application pool to spawn in a 32-bit mode)
Click OK.
p.s.: Don't forget to delete existing published files.
In Visual Studio 2015 you could easily set an MVC app to use full IIS by right clicking on the project & going to properties.
It's not clear how to do this in a vanilla .NET Core Web (MVC) project in Visual Studio 2017.
I can find nothing about this on Google - am I looking in the wrong place?
You can host it behind iis.
There are basicly four things you have to do besides having iis installed offcourse:
Install the .NET Core Windows Server Hosting bundle. It can be found here
https://go.microsoft.com/fwlink/?linkid=837808
Include a dependency on the Microsoft.AspNetCore.Server.IISIntegration package in the application dependencies. Incorporate IIS Integration middleware into the application by adding the .UseIISIntegration() extension method to WebHostBuilder().
Open cmd and run dotnet publish in your project
host published application on iis. It is important that in application pool the .NET CLR version is set to 'No Managed Code'.
There is a more detailed article on how to publish your application to iis.
https://learn.microsoft.com/en-us/aspnet/core/publishing/iis
I didn't find a way to do it directly from visual studio 2017.
Update:
you could use FlubuCore tool (C# fluent builder) to do step 3 and 4 for you automatically. You'd have to write flubu script that would look something like this(example is only for step 4):
protected override void ConfigureTargets(ITaskContext session)
{
session.CreateTarget("iis.install").Do(IisInstall);
}
private static void IisInstall(ITaskContext context)
{
context.Tasks().IisTasks()
.CreateAppPoolTask("SomeAppPoolName")
.ManagedRuntimeVersion("No Managed Code")
.Mode(CreateApplicationPoolMode.DoNothingIfExists)
.Execute(context);
context.Tasks().IisTasks()
.CreateWebsiteTask()
.WebsiteName("SomeWebSiteName")
.BindingProtocol("Http")
.Port(2000)
.PhysicalPath("SomePhysicalPath")
.ApplicationPoolName("SomeAppPoolName")
.WebsiteMode(CreateWebApplicationMode.DoNothingIfExists)
.Execute(context);
}
And then to integrate it with visual studio 2017 run this script with flubu dotnet cli tool in prebuild or postbuild event with command 'dotnet flubu iis.install'. I Would rather run the tool from command line explicitly.
You can find more information about flubu and how to get started here:
Choice for build tool: MSBuild, NANT or something else?
Solution and server configuration:
I have developed a fairly simple ASP.NET Core application. It consists of a core project file, created and built in Visual Studio 2017. The target framework is .NETCoreApp 1.1 and Platform target is x64.
It also contains two class library projects with target frameworks .NETStandard 1.4 and Platform target x64.
Due to a bug in VS2017's Web Deploy, I am publishing to file system, then copying the contents of PublishOutput to my IIS application's directory using FTP.
My server is Windows Server 2012 R2 with all relevant service packs and updates. DotNet Core runtimes have been installed.
The issue:
When I navigate to my site's URL in the browser, I encounter a bland HTML page which indicates the following:
HTTP Error 502.5 - Process Failure
Common causes of this issue: (lists things)
Troubleshooting steps: (lists things)
For more information visit http://go.microsoft.com/fwlink/?linkid=808681
Steps taken to resolve:
Needless to say, I've followed the instructions to resolve. The link given shows my error under the heading of Platform conflicts with RID.
The Event Viewer has an Error entry with the following:
Application 'MACHINE/WEBROOT/APPHOST/MY SITE' with physical root 'C:\inetpub\wwwroot\mysite\' failed to start process with commandline "dotnet" .\MySite.dll', ErrorCode = '0x80070002 : 0.
By opening an instance of cmd.exe at my site's folder, I can execute dotnet mysite.dll and it runs, hosting on http://localhost:5000. I can navigate to the site in a browser, as expected.
My Program.cs is as follows:
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
My Startup.cs is mostly uninteresting. Excepting some service definitions, my pipeline is:
app.UseCookieAuthentication();
app.UseRedditMiddleware(); // authentication middleware, custom
app.UseMvc();
app.UseStaticFiles();
Either the system wide %PATH% to the dotnet folder is not set (IIS runs as a different user) or you did not restart your server after installing ASP.Net Core Server bundle. You can find more some troubleshooting steps in my post about running ASP.NET Core applications with IIS.
so after .net core 1.0 got published I started a new console project and imported the code from a small prototype that is supposed to run without IIS. Besides having to use net46 in my project.json due the not-yet updated MongoDB.Driver, that worked fine. When I build the app in Visual Studio a small App.exe with a lot of dll is build and can be run fine locally without IIS.
I then noticed the option to build for IIS Express and thought that I can use the IIS on our server (IIS 6.2, Windows Server 2012 R2) too. It publishes fine with WebDeploy, but nothing happens after that. I was following this official guide. I installed the .NET core Windows Server Hosting bundle and everything appears to be in order, but when I browse to the url, I get a ERR_NAME_NOT_RESOLVED. Theapp.exedoes not appear in the Task Manager and I can't find any log file, although it is enabled in theweb.config. I can execute the app manually, but then it only listens on the defaultlocalhost:5000` address.
If I understood it correctly, the IIS is supposed to act as a reverse-proxy to the dotnet tool which starts a dll, but in my case it's already a compiled exe that works standalone. But I can't figure out how to build a dll from this app..
What am I doing wrong?
If you target full .NET Framework the application will be .exe and not .dll and it is fine. ERR_NAME_NOT_RESOLVED indicates that the url you provided in your browser could not be resolved and the request to the application was not made. AspNet Core Module starts the application on the first request and because the host could not be resolved the request was not made and the application was not started. Once you figure out why the name could not be resolved and you still have issues with making your application work with IIS take a look at my post which explains how things work and how to troubleshoot issues. This, however, only applies after the request can reach your application.
I want to run my ASP.NET 5 (beta7) application in Visual Studio 2015 on a specific domain, mydomain.com for example. How could it be achieved?
Hosting the published version would lose the Visual Studio debuging. Built in IISExpress launch profile do net let domain address change, just port number of localhost address.
EDIT: I've solved the problem with self-host, Microsoft.AspNet.Server.WebListener, but is there a way to do that with Windows IIS 8.5?
Publish your app to the file system and set up an IIS site as described in the documentation. You can use a custom domain if you override routing in the etc/hosts file.
In Visual Studio, go to Debug -> Attach to process
Check Show processes from all users
Find process called w3wp.exe and attach the debugger to it
Now your breakpoints will be hit as if hosted in IIS Express...
For me, I had to attach to the correct dnx.exe process not the w3wp.exe.
I found the correct dnx process by looking at the username it was running under. It was the app pool identity that I assigned the site to in IIS.
Update (2016-09-14):
With the release of .NET Core 1.0, I now must attach to a process that is named the same as my project. Eg. if my project is name TestWebApp then the process I attach to is named TestWebApp.exe.