Sunan an-Nasa'i 729
Grading supplied with this record: Sahih (Darussalam)
Narration text is preserved in its supplied Arabic and English. Translated interfaces and reading guides do not add narration translations in other languages.
إِذَا دَخَلَ أَحَدُكُمُ الْمَسْجِدَ فَلْيَقُلِ اللَّهُمَّ افْتَحْ لِي أَبْوَابَ رَحْمَتِكَ وَإِذَا خَرَجَ فَلْيَقُلِ اللَّهُمَّ إِنِّي أَسْأَلُكَ مِنْ فَضْلِكَ "
It was narrated that 'Abdul-Malik bin Sa'eed said:
"I heard Abu Humaid and Abu Usaid say: 'The Messenger of Allah (ﷺ) said: "When any one of you enters the Masjid, let him say: 'Allahumma aftahli abwaba rahmatik (O Allah, open to me the gates of your mercy). And when he leaves let him say: Allahumma inni as'aluka min fadlik (O Allah, I ask You of Your bounty).'"
Full reference and source
Sunan an-Nasa'i 729 In-book : Book 8, Hadith 42 English translation : Vol. 1, Book 8, Hadith 730
View source on Sunnah.com (opens in a new tab)