我正在使用jQuery來調用PageMethods。對於某些操作,當前的用戶憑證必須經過驗證,對於其他操作,我需要調用其他靜態方法。下面是一些示例代碼:是否在靜態PageMethod線程安全內部創建類的實例?
樣品#1
[WebMethod]
public static void PostComment(string comment)
{
UserAuth auth = new UserAuth();
if (auth.isAuthenticated)
{
//Post comment here...
}
}
樣品#2
[WebMethod]
public static string GetComment(int commentId)
{
commentDto comment = //get comment data from the database...
string friendlyDate = ConvertFriendlyDate(comment.commentDate);
return friendlyDate + " " + comment.text;
}
public static string ConvertFriendlyDate(DateTime commentDate)
{
string friendlyDate = //call static utility method to convert date to friendly format
return friendlyDate;
}
將使用這些類型的操作我是安全的?
我最好放棄頁面方法,只是爲我的AJAX請求調用一個單獨的ASPX頁面?
如果我從每個需要處理用戶登錄的頁面方法調用通用靜態方法會怎麼樣? – jpshook 2010-12-15 14:13:38