All perfect praise be to Allah, The Lord of the Worlds. I testify that there is none worthy of worship except Allah, and that Muhammad is His slave and Messenger.
A Muslim can pay his greetings at the grave of the Prophet by saying, “As-Salaamu ‘Alayka Ya Rasulul Allah” (Peace be upon you, O Messenger of Allah).
The companions of the Prophet used to say that expression. The evidence for this ruling is the Hadeeth that the Prophet said: “If anyone of you greets me, Allah returns my soul to me and I respond to the greeting.” [Abu Daawood]
Imam Ibn Hajar, may Allaah have His Mercy upon him, reported in his book Fathul-Baari that the chain of this Hadeeth is good. It is also reported that the Prophet said: “If one invokes blessings upon me at my grave, I hear it. If one invokes them from faraway, it will be conveyed to me.” [Abu-Ash-Shaykh in his book “Ath-Thawaab”. Imam Ibn Hajar graded its chain as good.
It is was reported that whenever Ibn ‘Umar entered the mosque of the Prophet he used to say: “Peace be upon you, O Prophet of Allah; peace be upon you, O Abu Bakr; and peace be upon you, O my father.” [Maalik and Ahmad]
Know that you should not supplicate Allah facing the grave of the Prophet ; instead, after greeting the Prophet you should face the Qiblah if you want to make Du'aa’. This practice is reported from Ibn ‘Umar, Anas and others. The four Imams are also of the same opinion.
Allah knows best.