MartinDuo
MartinDuo

Reputation: 753

Azure ASP,NET Core web app says "You do not have permission to view this directory or page"

I just upgrading my Azure service from free level to basic level to get more file storage space. But now accessing my first newly deployed Web app shows: "You do not have permission to view this directory or page." The deployment from Bitbucket worked. The kudu console shows everything loaded. I have 3 branches in my repo and three Azure apps defined, one for each. Two were deployed before upgrading and they are okay. The third was just deployed after the upgrade and has this problem. All three come from the same repo, and at this time all three branches are basically the same. All are the same basic ASP.NET Core 1.0 web app for each branch. I checked a lot of google pages, but none were helpful. Where do I go to fix this?

Upvotes: 4

Views: 7478

Answers (3)

Joshcodes
Joshcodes

Reputation: 8871

A frustrating experience making this work caused me to write this guide. What happens is your output may be missing some of the files needed, or be structured incorrectly, for IIS to launch your app. The issue can arise for different reasons.

Archive contains root directory.

When you create your zip file, make sure you are not archiving the root folder. What happens is your /home/site/wwwroot directory looks like:

/home/site/wwwroot
    --RootFolder
      --LaunchFile

When IIS is expecting

/home/site/wwwroot
    --LaunchFile

This is easy to fix by adding includeRootFolder: false to the ArchiveFiles@2 task.

- task: ArchiveFiles@2
  displayName: 'Archive files'
  inputs:
    includeRootFolder: false

Alternatively, if using the Web UI in the Root folder or file to archive section ensure that Prepend root folder name to archive paths is not checked.

Build vs Publish

Using the .NET Core task to build the project or solution can result in output that will not work in the /home/site/wwwroot directory. The key here is to choose the publish option, not the build option. build was working for us and then did not for one of our projects. Changing to publish made it work again.

- task: DotNetCoreCLI@2
  inputs:
    command: 'build'
    projects: 'MyProj/MyProj.csproj'
    arguments: '--output $(Build.BinariesDirectory)/WhereYouWantFilesForNextStep --configuration Release'

Instead, use the publish command.

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: publish
    arguments: '--configuration Release -o $(Build.BinariesDirectory)/WhereYouWantFilesForNextStep'

Zip File is not Mounted

Zip archives deployed to Azure are stored in

 Directory of D:\home\data\SitePackages

11/03/2021  06:24 PM    <DIR>          .
11/03/2021  06:24 PM    <DIR>          ..
11/03/2021  04:24 PM        66,278,978 20211103162437.zip
11/03/2021  06:24 PM        73,799,022 20211103182443.zip
11/03/2021  06:24 PM                18 packagename.txt

And, if the following Application Setting is provided:

WEBSITE_RUN_FROM_PACKAGE = 1

Then IIS will mount the zip archive specified in packagename.txt to the D:\home\site\wwwroot.

D:\home\data\SitePackages>cat packagename.txt
20211103182443.zip

Note that 20211103182443.zip is the name of one of the .zip file listed in D:\home\data\SitePackages directory. Now if WEBSITE_RUN_FROM_PACKAGE is toggled the contents of D:\home\site\wwwroot will change.

Useful Resources

Additional reading is available at Microsoft Docs: Run your app in Azure App Service directly from a ZIP package.

If you want to examine the contents of the zip file directly, PowerShell will work in the console provided at App Service > Development Tools > Console and has access to the Unzip command.

D:\home\data\SitePackages>PowerShell Unzip -l 20211103162437.zip
Archive:  20211103162437.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
    25600  2013-07-17 23:18   AForge.Genetic.dll
    ...

Upvotes: 0

Luke Puplett
Luke Puplett

Reputation: 45135

Your application files may not have deployed correctly. The root / gave me:

You do not have permission to view this directory or page.

When I tried a static HTML file I got:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

(This should have been served by the .NET Core static middleware.)

I'd been playing with my Azure Pipelines YAML and it was pushing the wrong files up in the deploy to Azure Web App task step, thing.

My app is .NET Core 2.2 in "Run-from-Zip" mode, now called Run-from-Package.

A path error in my YAML meant the package contained another subfolder with the package inside it, instead of it all being in the root of the package, if that makes sense.

Maybe this fascinating story helps someone.

Upvotes: 1

Bryan Roberts
Bryan Roberts

Reputation: 3479

This just means that the website didn't load so the IIS server is falling back and trying to load one of the html files it has in the list for startup which you wouldn't have since it should be loading up your site code instead, the directory listing is the last thing it could show and will fail in this scenario. Pay special attention to any differences in the deployment methods or any changes made to the Startup.cs file.

Upvotes: 3

Related Questions