Since this is an active area of research, it is unlikely for you to get consistent answers from physicians regarding this issue because each of us has our own opinion on it. Your primary care physician
combined with your dermatologist
would be best to help you manage your situation. For the average person, probably the best answer to this question is to get moderate sun exposure. In other words don't be afraid of the sun, go out in it occasionally, but don't try to get tan regularly. We are finding more evidence of the importance of vitamin D not just in the bones, but also in other areas of the body. So you are hearing correctly about the importance of vitamin D. In your particular situation since you have a history of skin cancer, I would err on the side of caution and limit exposure to the sun. You can balance this by taking vitamin D supplements so that you don't become deficient. Before making any decisions make sure to consult with both your primary care physician and dermatologist. They know your particular situation best and are most equipped to give you the best advice. Good luck.