By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,411 Members | 601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,411 IT Pros & Developers. It's quick & easy.

How can i redirect from a webmethod? - ASP.NET

P: 1
Hi;
I have an aspx page with a WebMethod to redirect the user to another page. The Default.aspx.cs is;

Expand|Select|Wrap|Line Numbers
  1. public partial class _Default : System.Web.UI.Page 
  2. {
  3.     [WebMethod]
  4.     public static void redirect_user()
  5.     {
  6.         HttpContext.Current.Response.Redirect("home.aspx");
  7.     }
  8. }
  9.  
and Default.aspx file;

Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml">
  5. <head runat="server">
  6.     <title>Untitled Page</title>
  7. </head>
  8. <body>
  9.     <form id="form1" runat="server">
  10.  
  11.         <script type="text/javascript">
  12.  
  13.         function Button1_onclick() 
  14.         {
  15.             PageMethods.redirect_user(redirectSuccess, redirectError);
  16.         }
  17.  
  18.         function redirectSuccess(result)
  19.         {
  20.             alert(result);
  21.         }
  22.  
  23.         function redirectError(error)
  24.         {
  25.             alert(error.get_message());
  26.         }
  27.  
  28.         </script>
  29.  
  30.         <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True" >
  31.         </asp:ScriptManager>
  32.         <div>
  33.             <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" />
  34.         </div>
  35.     </form>
  36. </body>
  37. </html>
  38.  
When i use HttpContext.Current.Response.Redirect("home.aspx") ; i have the "Thread was being aborted" error. And if i use the HttpContext.Current.Response.Redirect("home.aspx", false); overload i have the "Authentication failed" error. So how can i redirect from a webmethod?
Jan 21 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.