Reputation: 481
is it possible to get HTTP status code from current request (HttpRequest)? I am redirecting one page to another page with code 301. But when I am on redirected page, the page has in its response status code 200. In a browser I can see right code (301).
Upvotes: 3
Views: 5816
Reputation: 27142
When redirecting page to another (no matter if the status you redirect with 301 or 302 status), there are 2 requests:
When you check Response.StatusCode
on the redirecting page, it will be 301, but on the redirected page it will never be 301 (unless you're doing another redirection after the first one).
To get the HTTP status code from the response of current request, use:
HttpContext.Current.Response.Status // to get the string like '200 OK'
HttpContext.Current.Response.StatusCode // to get only the int value, e.g. 200
Upvotes: 10
Reputation: 981
To simply see the status code:
HttpContext.Current.Response.StatusCode
Upvotes: 3