Sometimes characters try to use spells or magical items to learn the alignment of a player character or NPC. This is a highly insulting, if not hostile, action.
Asking[]
Asking another character "So, what's your alignment?" is a rude question. At best, any character who is boorish enough to bring up the issue is likely to receive a very icy stare (turning to shocked horror from more refined characters).
Asking another character his alignment is futile, anyway—a lawful good character may feel compelled to tell the truth, but a chaotic evil character certainly won't. A chaotic evil character with any wit would reply "lawful good."
Player characters can only say what they think their alignment is. Once they have chosen their alignment, the DM is the only person in the game who knows where it currently stands. A chaotic good ranger may be on the verge of changing alignment—one more cold-blooded deed and over the edge he goes. But he doesn't know that. He still thinks he is chaotic good through and through.
Casting a Spell[]
Casting a spell to reveal a character's alignment is just as offensive as asking him directly. This is the sort of thing that starts fights and ends friendships. Hirelings and henchmen may decide that a player character who does this is too distrustful. Strangers often figure the spell is the prelude to an attack and may strike first.
Even those who consent to the spell are likely to insist that they be allowed to cast the same in return. Using these spells, besides being rude, indicates a basic lack of trust on the part of the caster or questioner.
Class Abilities[]
Some characters—the paladin, in particular—possess a limited ability to detect alignments, particularly good and evil. Even this power has more limitations than the player is likely to consider. The ability to detect evil is really only useful to spot characters or creatures with evil intentions or those who are so thoroughly corrupted that they are evil to the core, not the evil aspect of an alignment.
Just because a fighter is chaotic evil doesn't mean he can be detected as a source of evil while he is having a drink at the tavern. He may have no particularly evil intentions at that moment. At the other end of the spectrum, a powerful, evil cleric may have committed so many foul and hideous deeds that the aura of evil hangs inescapably over him.
Keeping Players in the Dark[]
Characters should never be sure of other characters' alignments. This is one of the DM's most powerful tools—keep the players guessing. They will pay more attention to what is going on if they must deduce the true motivations and attitudes of those they employ and encounter.