Reputation: 987
I have an ASP.Net Core 2.1.4 project and I can deploy this from within Visual Studio 2017 15.5.7 using the Publish menu item and Deploy to Azure type. This has been working just fine.
I am working on trying to deploy this project using a Bamboo Build/Deployment server and I have gotten my powershell script to upload the published files in a zip file to the Kudu Zipdeploy REST endpoint and I can see the deployment now in the Kudu list of deployments. This was worked out in this SO post with the help of David Ebbo.
However, now, when I try to access the API using Postman after using this powershell Kudu deployment method I get a 401 unauthorized status.
Publishing the exact same build using the VS2017 publish menu method allows me to access the API just fine so there is something still incorrect about my Kudu publish via Bamboo deployment and Powershell.
Here is my Powershell function;
Function Upload-ZipDeploy() {
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $PublishingUsername, $publishingPassword)))
$userAgent = "powershell/1.0"
if(!$SlotName)
{
$apiUrl = "https://$WebAppName.scm.azurewebsites.net/api/zipdeploy"
}
else {
$apiUrl = "https://$WebAppName-$SlotName.scm.azurewebsites.net/api/zipdeploy"
}
$filePath = $LocalPath
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method Post -InFile $filePath -ContentType "multipart/form-data"
}
I read a MS forum post talking about the zip endpoint and getting a 401 error after deployment where they solved it by putting a trailing / on the deployment URL. I tried that with my script but it did not make any difference.
Here is a snippet from the log stream showing that the deployment was successful;
2018-04-27T13:34:37 Finished successfully.
2018-04-27T13:34:37 Running post deployment command(s)...
2018-04-27T13:34:37 Deployment successful.
2018-04-27 13:34:37.160 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request starting HTTP/1.1 POST http://127.0.0.1:13601/iisintegration 0
2018-04-27 13:34:37.177 +00:00 [Information] Microsoft.AspNetCore.Hosting.Internal.WebHost: Request finished in 16.935ms 202
However, when I try to hit one of my API endpoints after this Kudu deployment, I get a 401 Unauthorized status.
When looking at the Log Stream for the API in Azure, I see the following;
018-04-27 13:37:32.814 +00:00 [Critical] Microsoft.AspNetCore.Hosting.Internal.WebHost: Hosting startup assembly exception
System.InvalidOperationException: Startup assembly
Microsoft.AspNetCore.AzureKeyVault.HostingStartup failed to execute. See the
inner exception for more details. ---> System.IO.FileNotFoundException:
Could not load file or assembly
'Microsoft.AspNetCore.AzureKeyVault.HostingStartup, Culture=neutral,
PublicKeyToken=null'. The system cannot find the file specified.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, Boolean
suppressSecurityChecks, IntPtr ptrLoadContextBinder)
at
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly,
StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean
throwOnFileNotFound, Boolean forIntrospection, IntPtr ptrLoadContextBinder)
at System.Reflection.Assembly.Load(AssemblyName assemblyRef)
at
Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices
(AggregateException& hostingStartupErrors)
--- End of inner exception stack trace ---
At this point, I am stuck. What am I missing here?
EDIT #1 4/30/18
I added the site extensions as suggested by David Ebbo. I am no longer getting the file not found error in the Azure log stream but I am still getting the 401 Unauthorized error when I try to access my API endpoints after a deployment using Kupu ZipDeploy. Again, I do not get this error and everything works fine if I deploy using VS2017 publish.
Here is my Azure extensions screenshot on my portal.
EDIT #2 - 4/30/18
OK, I believe that the issue is specifically related to the multi-target frameworks. I removed the projects from the solution that needed the multi-target setup and now I can deploy using ZipDeploy in Bamboo and I no longer get the 401 Unauthorized status when accessing the endpoints. I believe I can work with this option as the projects they were multi-targeted do not actually need to be deployed to Azure since they were DB related utilities and I can run them from a local server that targets the Azure database.
Upvotes: 0
Views: 1685
Reputation: 43193
I think I may know what your problem is, and it is not directly related to zipdeploy. Unlike the older Core runtimes, 2.1 is not installed on the VM (because it's preview). Instead, you need to install a site extension into your Web App. See this page for details (page was written for Preview 1, but it's the same deal for Preview 2).
I tried this using a clean Web App, default new Core 2.1 Preview 2 in VS, and zip deploy. And it ran fine after installing the site extension.
Upvotes: 1