yolip
May 27th, 2007, 10:37 PM
Hi, i tried to use Server.MapPath object to create a file in the server, but i got CS0120: An object reference is required for the nonstatic field, method, or property 'System.Web.UI.Page.Server.get' error. is that possible to do it in the WebMethod? What other solution i can use to output the error message, because i found hard to debug it.
the code i am using
[WebMethod]
static public string SendMessage(string msg, string roomID)
{
string spath="";
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
string res = "";
if (room != null)
{
res = room.SendMessage(msg, HttpContext.Current.Session["UserName"].ToString());
}
return res;
}
catch (Exception ex)
{
spath = Server.MapPath(@"logs\errorlog.txt");
TextWriter tw = new StreamWriter(spath );
tw.WriteLine(ex.Message);
tw.Close();
return "SendMessage error: " + ex.Message;
}
}
the code i am using
[WebMethod]
static public string SendMessage(string msg, string roomID)
{
string spath="";
try
{
ChatRoom room = ChatEngine.GetRoom(roomID);
string res = "";
if (room != null)
{
res = room.SendMessage(msg, HttpContext.Current.Session["UserName"].ToString());
}
return res;
}
catch (Exception ex)
{
spath = Server.MapPath(@"logs\errorlog.txt");
TextWriter tw = new StreamWriter(spath );
tw.WriteLine(ex.Message);
tw.Close();
return "SendMessage error: " + ex.Message;
}
}