User1520731567 posted
Hi aminsoraya,
every thin is okay in locally place but when i published the web config file. it not working at all
Since the <httpErrors> element was introduced in IIS 7.0,so I suggest you need to pay attention to your the version of IIS and using
IIS7+.
And make sure HTTP errors is enabled in IIS,like the picture:

If there is no such icon,please set it enable in windows features,like the picture:

I have test and work well based on your code both in local and publishing environment.
You could also try to add httpErrors by setting Error Pages in IIS,more details,please refer to:
https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httperrors/error
Best Regards.
Yuki Tao