0

在我们的 WebApplication 中,我们有很多 [WebMethod] 调用。为了安全起见,我们要检查它是否是登录用户(使用会话)。如何在不编写代码的情况下检查它WebMethods

例如。

[WebMethod]
public static bool WebMethodCall()
{// check if its a logged in user or not before executing the webmethod
  return true;
}
4

2 回答 2

0

我的第一个想法是使用自定义的 httpModule。然而,进一步的阅读表明使用 SoapExtensions 可以解决问题。参见示例: http ://www.hanselman.com/blog/ASMXSoapExtensionToStripOutWhitespaceAndNewLines.aspx

于 2013-10-09T05:17:28.403 回答
0

我通过示例给你这个答案我现在有名为 common.cs 的 web 服务

   public class Common : System.Web.Services.WebService
    {


     public Common () 

        {
           //here you can check your session so when ever your 
webmethod will be executed this code will call first then your webmethod

        }
//this webmethod will be executed after common
       [WebMethod]
      public static bool WebMethodCall()
         {// check if its a logged in user or not before executing the webmethod
               return true;
         }
[WebMethod]
      public static bool WebMethodCall1()
         {// check if its a logged in user or not before executing the webmethod
               return true;
         }
    }

所以解释是这样的,你有一个名为common的公共类,两个 webmethod webmethodcallwebmethodcall1添加你的公共 代码, 我希望这对你有帮助... :)

于 2013-10-09T05:14:44.903 回答