Reputation: 3252
As I am working on Asp.Net MVC 4 Web API
, I also need to return a View on specific condition. My flow is as given below:
So the point is, Is this possible to return both the LOGIN View (html)
and a WebResponse Status (200)
on different condition by the same WEB API method?
Thanks in advance.
Upvotes: 2
Views: 8995
Reputation: 2290
You could do two things:
AuthorizeAttribute
like in Jon Galloway's tutorial: Getting started with WebAPIWrap Your response data in HttpResponseMessage
and redirect user if needed. For example:
var responseMessage = new HttpResponseMessage<Stock>(null, HttpStatusCode.RedirectMethod);
responseMessage.Headers.Location = new Uri("http://www.mysite.com/login");
return responseMessage;
Upvotes: 3
Reputation: 13205
You should be able to, provided your method's return type is ActionResult
. After all, Web API just derives from Controller. The bigger question though: can your client handle such varried answers to the same question? Perhaps you should return 200 on success and non-200 on "go ask the other method for the view".
Upvotes: 0