问题描述
是否有可能创建MVC样式属性过滤器(如授权或调用HandleError)在ASMX Web服务的工作?
Is it possible to create MVC style filter attributes (like Authorize or HandleError) that work on ASMX Web Services?
具体来说,我对一些我的web方法执行自定义验证和想换的code到抛出异常的属性,如果认证检查失败。
Specifically, I perform custom authentication on a number of my web methods and would like to wrap the code into an Attribute that throws an exception, if the authentication checks fail.
富
推荐答案
由于ASMX也是服务器通过ASP.NET管道,你可以只使用的HttpModules,这给你很多的控制上的方式和出路
Since ASMX are also server by the ASP.NET pipeline, you could just use HttpModules, which give you a lot of control on the way in and the way out.
下面是一个参考和一个例子:
Here's a reference and an example:http://msdn.microsoft.com/en-us/library/aa719858%28VS.71%29.aspx
如果你想很MVC样,那么你会写一个自定义HTTP模块,检查的属性,如[授权]等。由于ASP.NET MVC是开源的,你可以只使用部分的web服务作为一个参考它们是如何检查的属性等,然后建立到您的HttpModule。
If you want to make it very "MVC-like" then you would write a custom http module that check the webservice for attributes such as [Authorize] etc. Since ASP.NET MVC is open source you may just use parts of that as a reference how they check for attributes etc and then build it into your HTTPModule.
HTH
亚历克斯
HTHAlex
这篇关于在ASMX Web服务MVC作风,过滤器,这可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!