如何返回特定的HTTP code(如401.X) [英] How to return more specific HTTP code (like 401.X)

查看:731
本文介绍了如何返回特定的HTTP code(如401.X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是一些扩展的HTTP codeS的一篇文章:

Here is an article about some extended HTTP codes:

IIS 7.0,IIS 7.5和IIS 8.0定义几个HTTP状态codeS的
  指示401错误的更具体的原因。下面具体
  HTTP状态codeS显示在客户端浏览器,但不
  在IIS日志中显示:

IIS 7.0, IIS 7.5, and IIS 8.0 define several HTTP status codes that indicate a more specific cause of a 401 error. The following specific HTTP status codes are displayed in the client browser but are not displayed in the IIS log:


      
  • 401.1 - 登录失败

  •   
  • 401.2 - 登录失败,服务器配置

  •   
  • 401.3 - 资源未经授权,由于ACL

  •   
  • 401.4 - 筛选器授权失败

  •   
  • 401.5 - 授权由ISAPI / CGI应用程序失败。

  •   

我需要一些自定义的扩展HTTP codeS这样的:

I need some custom extended HTTP codes like these:


      
  • 401.10 - 用户没有找到

  •   
  • 401.11 - 用户密码不匹配

  •   
  • 401.12 - 用户帐户被锁定

  •   
  • 401.13 - 用户帐户已过期

  •   
  • ...

  •   

如何从.NET MVC应用程序返回这些扩展的401错误codeS?

How to return these extended 401 error codes from .NET MVC application?

推荐答案

在你的操作方法您手动设置CS状态$ C $:

In your action method you set the status codes manually:

Response.StatusCode = 401;
Response.SubStatusCode = 10;

此外,您可以使用System.Net的的HTTPStatus code枚举:

Additionally, you can use the HttpStatusCode enumeration in System.Net:

Response.StatusCode = (int)HttpStatusCode.Unauthorized;

这篇关于如何返回特定的HTTP code(如401.X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆