Asp.net 在webMethod上使用FormsAuthentication
我有一个页面有一个评论部分。本节与Asp.net 在webMethod上使用FormsAuthentication,asp.net,ajax,jquery,webmethod,Asp.net,Ajax,Jquery,Webmethod,我有一个页面有一个评论部分。本节与WebMethod通信,以插入新注释 [WebMethod] public static bool insertComment(string commentString) { //userName validation here string userName = (FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Nam
WebMethod
通信,以插入新注释
[WebMethod]
public static bool insertComment(string commentString)
{
//userName validation here
string userName = (FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name);
return new CommentClass().InsertComment(commentString, userName);
}
问题是:“非静态字段需要对象引用”。
我知道我可以从隐藏字段或div
发送信息,但是,该信息字段可能很容易更改。
那个么,在服务器端,哪种方法可以用来知道哪个用户在发帖呢?
非常感谢
请求
对象是驻留在页面
中的实例,因此您需要引用才能在静态上下文中访问此对象。您可以使用HttpContext.Current.Request
访问此上下文中的Request
[WebMethod]
public static bool insertComment(string commentString)
{
//userName validation here
string userName =
(FormsAuthentication.Decrypt(
HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name);
return new CommentClass().InsertComment(commentString, userName);
}
Request
是需要引用的对象吗?是!很抱歉。。。这是唯一需要参考的部分。太好了!我要试试看。谢谢兄弟!