I do what is right. Why is my prayer not answered?

Okay, I am doing everything right, active in charitable causes, generous is sharing my wealth, faithful church-goer, earth-friendly, etc. - and all I get in response to my most earnest prayer: "I don't even know you. Get lost, sinner!"

This is the message in the Sermon on the Mount:

21 Not every one that saith unto me, Lord, Lord, shall enter into the kingdom of heaven; but he that doeth the will of my Father which is in heaven.
22 Many will say to me in that day, Lord, Lord, have we not prophesied in thy name? and in thy name have cast out devils? and in thy name done many wonderful works?
23 And then will I profess unto them, I never knew you: depart from me, ye that work iniquity. (Matt.)

The crux of the matter is "he that doeth the will of my Father which is in heaven." Jesus was making the point that doing good, or what you think is doing good, does not equate to doing the will of God. Why? you may ask. Well consider for a moment how many well-intended government programs have caused far more damage than good... or the over-bearing parent who has stiffled the child's creativity... or the church determined to protect its members from corruption...

How are we to know God's will? The first and most important step is to have a deep desire to know God's will, a recognition that it is more important to obey Him than it is to do good! 

"In patient obedience to a patient God, let us labor to dissolve with the universal solvent of Love the adamant of error, — self-will, self-justification, and self-love, — which wars against spirituality and is the law of sin and death." S&H

Then, whether or not we are certain of what God's will is, we proceed the best we can, continuing to listen for His guidance. Every step along this path is progress, for we, as ideas of God, are aligning ourselves with Principle, Love - and it does not get any better than that!