0

I have an ASP.NET website. A user can access the URL /partners/{partner-id} in my app. When that url is invoked, I do two things:

1) I want to log the partner ID and user that requested it and 2) Redirect the url to the partner's website.

My question is, which HTTP Status Code should I use? I was using 301. However, that introduced a problem where my logging code was getting skipped. I suspect its because a 301 represents a permanent redirect. However, I basically want to remain the middle man so that I properly log the details.

What HTTP status code should I use?

Thanks!

user70192
  • 12,138
  • 45
  • 148
  • 226

1 Answers1

0

Taking a look here:

https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

you should use the 302 status code. Two useful points about the 302 redirect:

Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests

This says by inferring that the redirect may be temporary, clients should always check the initial URI instead of going to the redirect URI as a default behavior, meaning they will pass through your logging system each time rather than going directly to the redirected URI on subsequent requests. The 302 response also states:

This response is only cacheable if indicated by a Cache-Control or Expires header field.

By default, the 301 redirect is cacheable unless you explicitly specify, but the 302 is not cacheable unless explicitly specified. However, it's probably a good idea to explicitly add in 'do not cache' headers to the redirect to let the client know that it should not be cached just in case you have a client that doesn't follow the default spec behavior. There are a number of other answers in stackoverflow regarding this, here's a decent one:

How to control web page caching, across all browsers?

Community
  • 1
  • 1
user3417917
  • 166
  • 5