【发布时间】:2010-12-14 15:19:00
【问题描述】:
我正在使用 jQuery 来调用 PageMethods。对于某些操作,必须验证当前用户凭据,而对于其他操作,我需要调用其他静态方法。下面是一些示例代码:
示例 #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 页面吗?
【问题讨论】:
-
如果我从每个需要处理用户登录的页面方法中调用一个通用静态方法,那会是线程安全的吗?
标签: c# asp.net static-methods pagemethods