Restricting a character's movement at a ledge?

Maybe a line trace to detect a ledge to start? I am trying to figure out the best way myself.