Reputation: 5670
I'm trying to do something like this article suggests in my MVC3 site. However, I'm not sure I can use the Response.End in my Action.
My question is, how can I return a 401 status code from my Action if the HttpContext.User == null?
public ActionResult WinUserLogOn(string returnUrl) {
var userName = string.Empty;
if (HttpContext.User == null) {
//This will force the client's browser to provide credentials
Response.StatusCode = 401;
Response.StatusDescription = "Unauthorized";
Response.End();
return View("LogOn"); //<== ????
}
else {
//Attempt to Log this user against Forms Authentication
}
Upvotes: 0
Views: 2854
Reputation: 30862
This should do what you want:
return new HttpUnauthorizedResult();
which will return a HTTP 401 to the browser. See the docs.
Upvotes: 5