How can I do 301 instead of 302 redirects when there are multiple domains sharing the same site hosted in IIS?

I have several domains sharing the same site and use a default.asp as the default file where I test the SERVER_NAME variable and use Response.Redirect to redirect to the home page of the site requested.

The problem is that this type of redirect causes 302 status code. Even when having a rewrite section in my web.config where I created one redirect rule for each site with redirectType="Permanent", the status code 302 is returned.

That is bad for ranking pages in Google’s index. Does somebody know a way to solve that problem and return 301 status code?