Click here to Skip to main content
15,439,117 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i am using the web method my programing and when i wanted to call response.redirected then i am getting the error that the thread exception so please
help the following is the code.

C#
[WebMethod]
 static public string UpdateUser(string roomID)
{
     try
     {
         ChatRoom room = ChatEngine.GetRoom(roomID);
         if (room != null)
         {
             string res = "";
             if (room != null)
             {
                 string s = string.Empty;
                 //if ((HttpContext.Current.Session["list"] != null) && (HttpContext.Current.Session["list"] != ""))
                 //{
                 //    s = HttpContext.Current.Session["list"].ToString();

                 //    foreach (char data in s)
                 //    {
                 //        if (data == Convert.ToChar(HttpContext.Current.Session["UserName"]))
                 //        {
                 //            res = room.UpdateUser(HttpContext.Current.Session["UserName"].ToString(), data);
                 //        }
                 //    }
                 //}
                 //else
                 //{

                     res = room.UpdateUser(HttpContext.Current.Session["UserName"].ToString());
                     string dataset3 = rid;
                     ChatRoom room1 = ChatEngine.GetRoom(dataset3.ToString());
                   string  prevMsgs = room1.JoinRoom1(HttpContext.Current.Session["UserName"].ToString(), HttpContext.Current.Session["UserName"].ToString());

                     string dataset = string.Empty;
                     Clslogin clslogin = new Clslogin();
                        DateTime  ds1 = DateTime.Now.Date;
                        string ds = ds1.ToString("MM/dd/yyyy") + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute;
                     if ((HttpContext.Current.Session["UserName"] != null) || (HttpContext.Current.Session["UserName"] .ToString()!= ""))
                     {
                         int userid=Convert.ToInt32(clslogin.groupuserid(HttpContext.Current.Session["UserName"].ToString()));
                         dataset = clslogin.usermessage(userid, ds, rid.ToString());
                         if (dataset != "")
                         {

                             HttpContext.Current.Response.Redirect("individual.aspx?Channel=" + rid.ToString() + "&User=" + HttpContext.Current.Session["UserName"].ToString() + "", false);
                             HttpContext.Current.ApplicationInstance.CompleteRequest();
                             //HttpContext.Current.Response.Write("<script type='text/javascript'>detailedresults=window.open('individual.aspx?Channel=" + rid.ToString() + "&User=" + HttpContext.Current.Session["UserName"].ToString() + "',null,'height=300,width=600,resizable=no,scrollbars=no,titlebar=no,status=no,toolbar=no,menubar=no,channelmode=no');</script>");
                         }
                         else
                         {

                         }
                     }
                     else
                     {

                     }
                 //}
             }

             return res;
         }
     }
     catch (Exception ex)
     {

     }
     return "";
 }
Posted
Updated 1-Mar-12 3:26am
v2
Comments
thatraja 1-Mar-12 9:27am    
what's the error message, update your question.
ZurdoDev 1-Mar-12 10:54am    
The issue is a WebMethod is a webservice, so you cannot redirect the user to a new place. A webservice is not called the same way a regular page is.

1 solution

If you call Response.Redirect within a try catch block, you must set the second argument of the call to false, otherwise you'll get a ThreadAbortException.

Moreover, a WebMethod in a web app is analogous to a method from a class library in a desktop application. It cannot control the UI. It should ideally return a value to the caller and the caller will have to do the redirect.
 
Share this answer
 
Comments
anupkulkarni85 2-Mar-12 0:50am    
I done that but getting the error as the systemInvalidoperationException--authentication failed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900