sql-serverdockerauthentication.net-2.0machinekey

Forms authentication failed for the request. Reason: The ticket supplied was invalid


I am trying to containerise a .NET framework 2.0 legacy application connecting to SQL Server on host outside the Docker, I am able to containerise the application, I can see the login page but when it tries to connect to SQL Server it gives error.

The type initialiser for 'class' threw an exception

Earlier I thought docker is unable to connect to host SQL Server but when I looked at the application logs inside docker, I found it has to do something with machine keys invalidation.

The error which I see in application log is:

Event code: 4005
Event message: Forms authentication failed for the request. Reason: The ticket supplied was invalid.
Event time: 29/07/2024 17:02:30
Event time (UTC): 29/07/2024 16:02:30
Event ID: 35ad1e99c62b4667b240c19a0c3e945f
Event sequence: 2
Event occurrence: 1
Event detail code: 50201

Application information:
    Application domain: /LM/W3SVC/1/ROOT-1-133667425492016462
    Trust level: Full
    Application Virtual Path: /
    Application Path: C:\inetpub\wwwroot\
    Machine name: EC7A5C0027E8

Process information:
    Process ID: 2624
    Process name: w3wp.exe
    Account name: IIS APPPOOL\DefaultAppPool

Request information:
    Request URL: http://localhost/default.aspx
    Request path: /default.aspx
    User host address: 192.168.1.21
    User:
    Is authenticated: False
    Authentication Type:
    Thread account name: IIS APPPOOL\DefaultAppPool

Name to authenticate:

Custom event details:

Solution

  • Finally, I found the solution, there was no issue regarding the sql server. Everything was set perfectly, like tcpip settings in sql server configuration, firewall inbound rule for 1433 port, allow remote connection in sql server etc.

    The actual problem was that I was unable to see the logs to find out where the problem is happening. After so many days I found that app.log resides in inetpub/wwwroot directory which has got detailed exception log about the error which guided me that there is a problem in the directory structure in dockerfile, due to which the application is unable to find the localisation and resources folder.

    I corrected my dockerfile to create correct directory structure under inetpub/wwwroot and it worked.

    Anyone struggling with the error with dockerfile, here is my version:

    FROM mcr.microsoft.com/dotnet/framework/aspnet:3.5-windowsservercore-ltsc2016
    
    WORKDIR /inetpub/wwwroot/***/***/auth
    COPY auth/. .
    
    WORKDIR /inetpub/wwwroot/***/**/<app dir>/
    COPY admin/. /inetpub/wwwroot/**/**/<app dir>/.
    
    RUN c:\Windows\System32\inetsrv\appcmd.exe add app /site.name:"Default Web Site" /path:/***/**/<app dir>/physicalPath:C:\inetpub\wwwroot\***\***\<app dir>