What I've learned over the years is that it's best to appear modest in these situations. If I'm working on a group project and someone tells me what a good job I did, I'll say, "It was really X who did all the work. I just helped." If I am working alone, then the compliment is met with, "Oh, I got lucky, I guess." If they insist that I really did a great job, I respond with, "Don't give me too much credit. I worked on a similar project last year." (This last one is a little white lie I can live with.)
But if I'm not sure if it's a legitimate compliment, and maybe the person is being sarcastic, I respond, in my brightest voice and a big smile on my face, "Why, thank you!"
Sometimes, though, I run into someone who thinks they're being helpful if they can get me acknowledge the compliment, as if there were any gain to me bragging about my work. These people can be quite insistent. I really have no idea how to handle these situations, so I generally respond with, "Well, I'd love to stand around here all day listening to you talk about how great I am, but I have work to do." Then I walk off. Chances are, if these people can see you're uncomfortable and still insist on badgering you, it probably doesn't matter what you say to them. They just won't get it.