Physical path in Azure WebJobs - azure

I am trying to deploy webjob in azure. It is an existing console app that does a file copy using SFTP.
The appsetting in the app.config file is like below :
<add key="IdentityFile" value="C:\Temp\Uploads\UploadTest.ppk"/>
I know I have to set this in AppSettings section of the AppService but I am not sure what is equivalent to "C:\Temp" in Azure.
Could someone please guide me? Thank you

In Azure App Service, you can still rely on %TMP% to find the temp folder. The folder it goes to is D:\local\Temp, so you could change your config to D:\local\Temp\Uploads\UploadTest.ppk.
Note that you can change this by setting an IdentityFile App Setting in the Azure Portal, instead of changing it in the physical app.config file.

Related

Deployed app using Zipdeploy UI on Azure throws an error

i can deploy an app using Azure service extension in visual studio code which also creates web.config file and the app works fine, but when i try to upload the ZIP file using ZIPdeployUI and manually add the web.config the app throws an error "You do not have permission to view this directory or page". The difference is using Visual studio code the files are uploaded straight into /wwwroot folder and with ZipdeployUI it creates another folder that was zipped on local system.
You do not have permission to view this directory or page.
That is basically a hint that Azure encounter an error while running your web app. Since it's in production, it does not show any useful error messages. For testing/debugging purposes you can turn on the Azure detailed messaging, and turn it back off when it's ready for production. To do so, you have to follow these two steps,
Log in to Azure > App Services (left side menu) > Your Web App > App Service logs (search box is at the top if you can't find it), then turn on Detailed Error Messages or turn on all of the logging options, up to you.
Now add the following in your Web Config file,
In your Web Config file add <customErrors mode="Off" /> BEFORE system.web closing tag, </system.web>. Similarly, add <httpErrors errorMode="Detailed"></httpErrors> BEFORE </system.webServer>. Finally, upload the Web Config to Azure and cross your fingers.
If you follow the steps correctly, that will show the error messages in detail which takes you to figure out the issue.
Few Error Cases-Resolutions were:
You do not... this directory... this error comes when you have restricted IP on IIS Config. Check your web.config file and add your IP address in security section like:
<security>
<ipSecurity allowUnlisted="false">
<clear />
<add ipAddress="192.168.250.70" allowed="true" />
</ipSecurity >
</security>
Remove it if you do not want to restrict any IP address.
Check the zip is unpacked in the path Site>wwwroot>, else try restarting your function or web app.
You might need to tweak this depending on how your application structure looks like after the build like site\wwwroot\dist\, but if you have the app name in the folder structure, you might need to: site\wwwroot\dist\<app-name>\
Sometimes azure active directory authentication was created by Function App / Authentication automatically like (MS Graph - User.Read, Azure Service Management -user_impersonation). If yes, removing those will work to access the directory.

Azure DevOps - Azure App Service deploy - Adds Application settings WEBSITE_RUN_FROM_PACKAGE causes CSS to not load

In Azure DevOps we have the following Azure App Service deploy task in our release pipeline:
This works good but it adds Application settings WEBSITE_RUN_FROM_PACKAGE = 1 for Azure App Service
The web application starts but for some reason /lib/ionic/release/css/ionic.min.css is not loaded with this setting.
If I remove WEBSITE_RUN_FROM_PACKAGE and upload the exact same files via FTP everything works as expected.
I know WEBSITE_RUN_FROM_PACKAGE comes from the .zip file deployment but is there anyway to modify the task to simply upload a folder or do I need to use the FTP upload task then? I know WEBSITE_RUN_FROM_PACKAGE makes wwwroot read-only but what could be causing this? With this setting a GET to the resource simple gives the following error:
The resource you are looking for has been removed, had its name
changed, or is temporarily unavailable.
https://learn.microsoft.com/en-us/azure/azure-functions/run-functions-from-deployment-package
Solved the upload with FTP Upload task
https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/ftp-upload?view=azure-devops
However after doing this I still had the same error.
Went into App Service Console and there I could not see the file at all.
I finally solved it by looking at the file name, /lib/ionic/release/css/ionic.min.css. In our .gitignore file we exclude [Rr]elease/. Adding a ignore with !AppFolder/** solved it so the files were added to git.

How do I get into the folder of a Web App in Azure

Recently I am trying to use:
func azure functionapp publish WebAppName --publish-local-settings -i
to publish local.settings.json to a web app (actually an Azure function) but I get this error message:
Unable to find project root. Expecting to find one of host.json in project root.
I have logged in to Azure with az login but it looks like I need to get into the folder where I have deployed the Azure function where all those json files are.
A little background, we are using Octopus Deploy to deploy to an Azure function. After the deployment, we want to add a step so that the local.setting.json will be used to populate app settings.
So how do we change the current folder to be in the Azure function root where all those json files are?
Thanks a lot in advance!
You need to go to your local function project folder to run the command, for example, my function project is under MyFunctionProj folder.
Execute the command
func azure functionapp publish tonyfunc --publish-local-settings -i --publish-settings-only
By the way, if you just want to update the settings, you need add --publish-settings-only parameter.
Reference:
Core Tools development

public Azure Function that can overwrite and save files in wwwroot of other azure applications? in particular aspx and run.csx files

possible to have a public Azure Function that can overwrite and save code files in wwwroot of other azure applications? in particular aspx and run.csx files?
I understand the security risks, but the idea to have the Azure Function do this with a hard coded specific service account with rights and for two very specific aspx and run.csx files.
Neither of these requires a compile step in the Azure portal UI and wonder about that as well.
Just a question, not looking for best practices or reasons why we should not do this.
If you dont need to compile, just save the code and files,that is no problem.
But it can only be saved, it will not be a real web app, just some files.
You can use zip deploy or FTP to deploy the azure function app to azure and include the files you want to save.
If you Use zip deploy, just zip the files and code with the function app. And then use this command to deploy them to azure:
Azure CLI:
az functionapp deployment source config-zip -g <resource_group> -n <app_name> --src <zip_file_path>
PowerShell:
Publish-AzWebapp -ResourceGroupName <group-name> -Name <app-name> -ArchivePath <zip-file-path>
This is offcial doc:
https://learn.microsoft.com/en-us/azure/azure-functions/deployment-zip-push
Or you can use FTP to upload files.
Go to this place to get the host name:
Go to this place to get the username and password:
And then use them to connect to your function physical path:
At last you can upload anything to the wwwroot of your function app on azure.
This is the offcial doc:
https://learn.microsoft.com/en-us/azure/app-service/deploy-ftp
If you just want to rewrite the file under wwwroot folder, yes this is possible.
I have two function in the portal, in the HttpTrigger1 function I rewrite the HttpTrigger2 content. Below is HttpTrigger2 original content.
Below is HttpTrigger1 code, write a string to HttpTrigger2 run.csx.
Here is the result, after running HttpTrigger1, the HttpTrigger2 content is changed.

Get publication path when publishing Azure

I followed this thread to create a virtual directory in Azure Cloud Services: Windows Azure creating virtual directory to local storage.
It works fine but I'm not able to get "localResourcePath" with the path Azure located the files.
Where do I have to set "MyResource"?
Thanks in advance.
"MyResource" is a LocalStorage resource you define in your CSDEF file - http://msdn.microsoft.com/en-us/library/azure/ee758711.aspx.
You would add the following to your CSDEF (changing sizeInMB as appropriate):
<LocalResources>
<LocalStorage name="MyResource" cleanOnRoleRecycle="false" sizeInMB="1000" />
</LocalResources>

Resources