They are both correct.
Michael Swan's Practical English Usage ( the British grammarian's 'bible' ) says:
'After way (meaning 'method/manner') we can use an infinitive structure or of … ing. There is no important difference between the two structures. There is no way to prove / of proving that he was stealing.'
So 'no important difference'. But I would agree with Ashley's suggestion that the infinitive version may imply that it is perhaps the only way, whereas the 'of + ..ing' construction may imply that there are alternative ways. But the distinction is so subtle that it probably isn't worth worrying about.