The error can be caused due to the user ASPNET don't have access to IIS metabase, or the ASP.NET is not installed in the IIS properly. To fix this issue, start the command prompt and go to
aspnet_regiis -ga ASPNET
Replace ASPNET with any other user that might be runnig the ASP.NET.
This will install the ASP.NET into the IIS.
Note: You might need to recycle the Application Pool. Source: ASP.NET IIS Registration Tool (Aspnet_regiis.exe)