How can I return a HTTP 401 from a WCF service?
相关问题
- Angular RxJS mergeMap types
- Google Apps Script: testing doPost() with cURL
- How to instantiate Http service in main.ts manuall
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- How to make a .svc file write to asp.net Trace.axd
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- WCF发布Windows服务 POST方式报错 GET方式没有问题 应该怎么解决?
- XCopy or MOVE do not work when a WCF Service runs
- Is a unicode user agent legal inside an HTTP heade
- git: retry if http request failed
- Flutter - http.get fails on macos build target: Co
- Could not find default endpoint element that refer
- The 'DbProviderFactories' section can only
If you are programming a REST-service it can be done this way:
Depending on when you need to do the authorization check, you could do it in an
HttpModule
using something like the following:Notes:
If you're using the WebServiceHost2 factory from the WCF REST Starter Kit, you can also throw specific
WebProtocolException
and specify a HTTP return code:(source: robbagby.com)
(source: robbagby.com)
(source: robbagby.com)
There's also a
HttpStatusCode.Unauthorized
which corresponds to the 401 status code.See Rob Bagby's excellent blog post Effective Error Handling with WCF REST for more detail on the various ways of specifying HTTP return codes. (screenshots are from Rob's blog post - he deserves all the credit for this.)