- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一个 Restful API,我需要在发出实际的 DELETE 请求之前检查授权。所以我认为使用 HEAD 方法作为预检检查会很好。
我预计使用 HEAD 方法的未经授权的请求将返回没有正文的 401/403 响应。然而,事实证明 WebApi2 崩溃并出现以下异常并关闭连接:
Exception caught: 'System.Net.ProtocolViolationException' in System.dll ("Bytes to be written to the stream exceed the Content-Length bytes size specified.")
其他 HTTP 方法(DELETE、GET)似乎工作正常 - 返回 401 响应。
我可以通过 GET 请求来解决它,但这似乎是 WebApi 中的一个错误。 AuthorizeAttribute总是添加一个内容,不管原来的请求方法是什么。
我的问题是:这是错误还是预期的行为,我为什么不应该在这里使用 HEAD 方法?
这是一个重现该问题的示例程序:
namespace OwinServer
{
[Authorize]
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new[] { "value1", "value2" };
}
//HEAD api/values
public void Head()
{
}
//DELETE api/values
public void Delete()
{
}
}
class Program
{
static void Main(string[] args)
{
var baseAddress = "http://localhost:9000/";
// Start OWIN host
using (WebApp.Start(baseAddress, Configuration))
{
Console.WriteLine("Host started");
Console.ReadLine();
}
}
public static void Configuration(IAppBuilder appBuilder)
{
// Configure Web API for self-host.
var config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(config);
}
}
}
可以使用 PowerShell 测试该行为:
失败的示例请求:
Invoke-WebRequest -Uri 'http://localhost:9000/api/values' -Method HEAD
有效的示例请求:
Invoke-WebRequest -Uri 'http://localhost:9000/api/values' -Method DELETE
最佳答案
这个已经讨论过了https://github.com/aspnet/AspNetWebStack/issues/189 .似乎他们希望您最终处理它。
关于c# - 在 WebApi2 + Owin 中使用 AuthorizeAttribute 时,HEAD 请求因 System.Net.ProtocolViolationException 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45377956/
我正在构建一个 MVC 5 应用程序。我需要根据 AD 和 sql 数据库或 Web 服务对人员进行身份验证。 要求是如果一个人登录到公司网络或通过 VPN 连接,我必须在不要求凭据的情况下登录它们。
有没有办法从 WindowsAzureActiveDirectoryBearerAuthenticationOptions 等扩展中调试 OWIN 中间件,并确切了解请求被拒绝的原因(例如,没有 to
我们对 Nancy/Owin 托管的 api 有一种奇怪的体验 - 当 URL 查询字符串超过 255 个字符时,Nancy 返回 400 Bad Request。 知道如何解决这个问题吗? 最佳答案
正确的处理方式是什么Content-Length在 Owin 中间件中编写正文内容时? 目前我们正在使用 context.Response.Write(data); // data is a stri
我目前正在构建一个包含多个 OWIN 中间件的库。这些中间件应该按照一定的顺序执行。在 OWIN 的第一个版本中,有 IAppBuilder界面。然而IAppBuilder不再是 OWIN 的一部分,
我们的 Mvc/WebAPI 解决方案目前有四个我们已在 ADFS3 中注册的可信身份提供者。我们的用户可以通过直接链接使用这些身份提供者中的每一个,有效地解决 ADFS 可能创建的任何家庭领域 co
实际上我知道有关于 KATANA 好处的主题和问题,我知道它们,但我的问题是 Katana 在业务方面可以为我做什么?比如为什么我应该使用 WEB API 作为一个单独的模块(中间件)?它可以与哪个中
IOwinContext 中似乎没有 HTTP Referrer,我需要捕获它。获取该特定变量的正确方法是什么? IOwinContext 有几个 Typed PEM,但我没有特别看到 referer
我正在开发一个使用 Katana 公开自托管 WebAPI 服务的应用程序。我想以类似于 IIS 允许单个网站下的多个应用程序的方式来管理内容。 例如,我可能有三个包含 web api 内容的文件夹:
从 asp.net 6 开始,将没有名为 global.asax 的文件,但 global.asax 有许多事件,例如 · Application_Init · 申请_开始 · Session_Sta
我从 http://blogs.msdn.com/b/webdev/archive/2013/11/22/debugging-owin-app-or-framework.aspx 得到了演示代码,它显
我正在使用 Facebook Owin 身份验证并或多或少地遵循 Microsoft 示例。我或多或少地关注第一次用户登录,一切正常。但如果他们退出并重试,似乎之前的 .AspNet.Correlat
我已经阅读了很多关于此的帖子,但仍然无法使其正常工作。我正在使用 Visual Studio 2013。我创建了一个新的 MVC 5 项目,并认为使用新的 facebook 登录集成会很酷。它在我的
在使用 OWIN 请求管道创建 ApplicationUserManager 时,我在使用依赖注入(inject)创建自定义 UserStore 时遇到问题。 背景 我正在尝试将 Web 应用程序中的
我试图了解 Microsoft.Owin.Security.ActiveDirectory 的用途,但似乎找不到任何文档、测试,甚至 much以文章的方式。 这个包的实际用途是什么?我试图使用它来创建
如果我使用 OwinMiddleware 和 IOwinContext 等 Microsoft.Owin 类型构建 OWIN 中间件,我的中间件是否可以与非 Microsoft Owin 主机/服务器
我在 IIS 7.5 中部署了一个 Owin 中间件身份验证项目作为 Web 应用程序但问题是 Startup.cs 没有被调用。 [assembly: OwinStartup(typeof(Auth
据我所知Microsoft.Owin.Host.SystemWeb允许我在 IIS 上运行 OWIN 应用程序,但今天我发现了另一个名为 Microsoft.Owin.Host.IIS 的包(据我从其
有谁知道将 Owin Asp.Net Identity Cookie 身份验证(本地数据库)与 Owin OpenId 身份验证(云)混合的一个很好的例子?然后用户可以选择通过创建新用户和密码(存
我将 MVC 5 与 OWIN 身份验证一起使用。 这是我的 StartUp.cs 的代码。 public void ConfigureAuth(IAppBuilder app) {
我是一名优秀的程序员,十分优秀!