You got all the way to the interview phase of the search for a job, contract assignment, or new client/customer. Then, you were knocked out the box. That rejection, however, can get you closer to achieving your professional goal next time. That is, if you leverage it to improve your interviewing skills.
The first step in the process is to go over everything, from what you wore to how you comported yourself in the waiting room to what you said or didn't say. That's called "doing an autopsy" on what didn't go as planned.
What, in retrospect, have you decided was a mistake? What could have been done better? What were "sins of omission," for example, not suggesting to the interviewer how a problem might be solved? On the next interview you will apply those lessons.
In addition, yes, ask the person or people who interviewed you how you can improve in the future. That way of framing it lets them off the hook from getting trapped in legalities. For example, if they just point to your behavior in the interview process, they don't indicate that you were rejected because of your age, ethnic origin, or sexual orientation. Since there is no danger, there might be more readiness to provide the insight you need.
A decade ago I asked the head of a non-profit for feedback on why she didn't hire me for the full-time communications position. She took me out to lunch and gently explained the fit wasn't there for me to function in an organization. I was the entrepreneur type. To that lunch she had brought my first client.