MVC Style Filters on ASMX Web Services, is it possible?

北慕城南 提交于 2019-12-11 06:26:55

问题


Is it possible to create MVC style filter attributes (like Authorize or HandleError) that work on ASMX Web Services?

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.

Rich


回答1:


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(VS.71).aspx

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 Alex




回答2:


You can mimic some effects. Remembering that ASMX web services just wrap any public method, you can use things like the PrincipalPermissionAttribute to secure your services.



来源:https://stackoverflow.com/questions/1508216/mvc-style-filters-on-asmx-web-services-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!