The easy solution for this error is:
Open visual studio command prompt and type this command
aspnet_regiis -ga \username
Here username is usually aspnet
if this doesn't work than use this command
aspnet_regiis -i
alternatively you can copy and paste this command into windows command prompt
%windir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i
this will fix your problem