Mishap
Mishap

Reputation: 283

Is it possible to retrieve the HTTP Status Response Code in an MVC View?

Is it possible to retrieve the HTTP Status Response Code in an ASP.net MVC View?

For instance, I can get the server name with @Environment.MachineName.

Is there a similar, easy way to get the http status response code for the current page?

If not, what about using Javascript?

If not, is there any way to do it without issuing a new request? I want to grab this information off of every page view, and I'd rather not double the hits just to do it.

Thanks

Upvotes: 2

Views: 3331

Answers (2)

SLaks
SLaks

Reputation: 887459

Use

Context.Response.StatusCode

Upvotes: 3

hunter
hunter

Reputation: 63522

Response.StatusCode is on the WebPageRenderingBase

So you can write this on any view:

@{ Response.StatusCode }

http://msdn.microsoft.com/en-us/library/system.web.webpages.webpagerenderingbase(v=vs.111).aspx

Upvotes: 4

Related Questions