Sunday, February 16, 2020

Cloud Web App TroubleShooting


  1. Capture a dump on Kudu

  1. The auto heal feature with this you can set up a custom mitigation actions to run when some conditions are met( You can configure what you need). You can find more information about this feature on the following articles and how to collect the memory dump using this feature:


  1. You can capture a dump on the portal you can attached a document on this email with a step by step guide.

  1. For the crash dump that you asked me. You can use the crash diagnose tool and you can find more details on the following articles:


Thursday, January 23, 2020

Check File Permission for App Service Files in Azure


Below is the permissions output of files in the wwwroot directory that I ran with a Powershell command in Kudu site. So if you ever see the issue again and you ensure stdoutLogFile="\\?\%home%\LogFiles\stdout" but still have issues, you may compare your Powershell permissions output of your wwwroot directory to mine to see if they have same access control:

You should use this when your web application isn't starting and giving you the permission error. 

Navigate to your Kudu site (yourApp.scm.azurewebsites.net) --> Debug Console --> PowerShell --> navigate to wwwroot directory





(Run the PS command below to show all files access control and pipe output to avoid PS truncation of the results)

Dir | Get-Acl | Format-List

You can compare your output to mine:
F

PS D:\home\site\wwwroot> Dir | Get-Acl | Format-List
Dir | Get-Acl | Format-List​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\wwwroot​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;OICIID;0x1301ff;;;WD)(A;OICIID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\appsettings​
         .Development.json​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\appsettings​
         .json​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\hostingstar​
         t.html​
Owner  : BUILTIN\Administrators​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:BAG:S-1-5-21-2996674325-4160296812-1073090115-513D:AI(A;ID;0x1301ff;​
         ;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\web.config​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.deps.json​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.dll​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.pdb​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.runtimeconfig.json​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.Views.dll​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)​
Path   : Microsoft.PowerShell.Core\FileSystem::D:\home\site\wwwroot\WebApplicat​
         ion4.Views.pdb​
Owner  : O:S-1-5-21-2996674325-4160296812-1073090115-501​
Group  : G:S-1-5-21-2996674325-4160296812-1073090115-513​
Access : Everyone Allow  DeleteSubdirectoriesAndFiles, Modify, Synchronize​
         BUILTIN\Administrators Allow  FullControl​
Audit  : ​
Sddl   : O:S-1-5-21-2996674325-4160296812-1073090115-501G:S-1-5-21-2996674325-4​
         160296812-1073090115-513D:AI(A;ID;0x1301ff;;;WD)(A;ID;FA;;;BA)


Sunday, December 15, 2019

Delete files older than x days on Azure Web App



Get files older than 30 days.
forfiles -s -m *.* -d -30 -c "cmd /c echo @file" (All files)


Once results look ok, change echo to delete. 
forfiles -s -m *.* -d -30 -c "cmd /c del @file"

Change *.* to * if you want to include directories. 

to have a condition


forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==TRUE echo @file is a directory"

Remove all directories from the current directory older than 3 days.

forfiles -s -m * -d -3 -c "cmd /c if @isdir==TRUE RMDIR /S /Q @file"


Tuesday, October 15, 2019

HangFire Ioc Contaner - Job Schedular

Nuget :
Hangfire.AspNetCore
Hangfire.SqlServer (Redis can also be used)

services.AddHangfire(x => {
                var options = new SqlServerStorageOptions
                {
                    PrepareSchemaIfNecessary = true,
                    QueuePollInterval = TimeSpan.FromSeconds(5)
                };
                x.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"), options);
                });


 //services.AddHangfire(configuration => {
            //    configuration.UseStorage(
            //        new MySqlStorage(
            //            "server=127.0.0.1;uid=root;pwd=root;database={0};Allow User Variables=True",
            //            new MySqlStorageOptions
            //            {
            //                TablesPrefix = "Hangfire"
            //            }
            //        )
            //    );
            //};


//https://docs.hangfire.io/en/latest/configuration/using-sql-server.html
            //https://docs.hangfire.io/en/latest/configuration/
            //https://docs.hangfire.io/en/latest/getting-started/aspnet-core-applications.html
            GlobalConfiguration.Configuration.UseSqlServerStorage(Configuration.GetConnectionString("DefaultConnection"));
            GlobalConfiguration.Configuration.UseActivator(new ServiceJobActivator(serviceProvider.GetService<IServiceScopeFactory>(), serviceProvider));
            //GlobalConfiguration.Configuration.UseActivator(new HangfireActivator(serviceProvider));
            app.UseHangfireDashboard("/hangfire", new DashboardOptions
            { 
                
            });
            app.UseHangfireServer(new BackgroundJobServerOptions { 
                 WorkerCount= 1
            });

Job Activator
public class ServiceJobActivator : JobActivator
    {
        readonly IServiceScopeFactory _serviceScopeFactory;
        private readonly IServiceProvider _serviceProvider;

        public ServiceJobActivator(IServiceScopeFactory serviceScopeFactory, IServiceProvider serviceProvider)
        {
            if (serviceScopeFactory == null) throw new ArgumentNullException(nameof(serviceScopeFactory));
            _serviceScopeFactory = serviceScopeFactory;
            _serviceProvider = serviceProvider;
        }

        public override JobActivatorScope BeginScope(JobActivatorContext context)
        {
            return new ServiceJobActivatorScope(_serviceScopeFactory.CreateScope());
        }

        public override object ActivateJob(Type type)
        {
            return _serviceProvider.GetService(type);
        }
    }


public class ServiceJobActivatorScope : JobActivatorScope
    {
        readonly IServiceScope _serviceScope;
        public ServiceJobActivatorScope(IServiceScope serviceScope)
        {
            if (serviceScope == null) throw new ArgumentNullException(nameof(serviceScope));
            _serviceScope = serviceScope;
        }
        public override object Resolve(Type type)
        {
            return _serviceScope.ServiceProvider.GetService(type);
        }
    }


In the service, inject IBackgroundJobClient backgroundJobs and use 
_backgroundJobs.Enqueue<ISampleService>(s => s.CallFunction());