0

私たちの WebApplication には、多くの [WebMethod] 呼び出しがあります。セキュリティの目的で、ログインしているユーザーかどうか (セッションを使用して) を確認したいと考えています。all 内にコードを書かずにチェックするにはどうすればよい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

私は今、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 という名前の共通クラスがあり、2 つの webmethod webmethodcallwebmethodcall1 が共通のコードを共通 に追加します。

于 2013-10-09T05:14:44.903 に答える
0

私の最初の考えは、カスタム httpModule を利用することです。ただし、さらに読むと、SoapExtensions を使用するとうまくいくことがわかります。例を参照してください: http://www.hanselman.com/blog/ASMXSoapExtensionToStripOutWhitespaceAndNewLines.aspx

于 2013-10-09T05:17:28.403 に答える