No, that code won't help. Moreover it can be really problematic for users behind a proxy: the HTTP requests will be issued by the proxy server, so the client IP will be the same for every PC behind it.
The DoS prevention is done on the infrastructure, outside your application's code. See this article as an example on IIS: http://m.windowsitpro.com/windows/q-does-microsoft-iis-70-include-feature-protect-iis-web-server-denial-service-dos-attacks-do
So, in short, the DoS prevention is normally done by the hosting provider.