Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

How can i redirect from a webmethod?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
omer013 - 21 Jan 2008 14:52 GMT
Hi;
I have an aspx page with a WebMethod to redirect the user to another page.
The Default.aspx.cs is;

public partial class _Default : System.Web.UI.Page
{
   [WebMethod]
   public static void redirect_user()
   {
       HttpContext.Current.Response.Redirect("home.aspx");
   }
}

and Default.aspx file;

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Untitled Page</title>
</head>
<body>
   <form id="form1" runat="server">
       
       <script type="text/javascript">
       
       function Button1_onclick()
       {
           PageMethods.redirect_user(redirectSuccess, redirectError);
       }
       
       function redirectSuccess(result)
       {
           alert(result);
       }
       
       function redirectError(error)
       {
           alert(error.get_message());
       }

       </script>
       
       <asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="True" >
       </asp:ScriptManager>
       <div>
           <input id="Button1" type="button" value="button" onclick="return
Button1_onclick()" />
       </div>
   </form>
</body>
</html>

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?
bruce barker - 21 Jan 2008 16:43 GMT
you can not redirect the client from a web method. the redirect only
redirects the method call. your web method should return the redirect url,
and javascript can do the redirect.

  document.location.href = redirectUrl;

-- bruce (sqlwork.com)

> Hi;
> I have an aspx page with a WebMethod to redirect the user to another page.
[quoted text clipped - 57 lines]
> HttpContext.Current.Response.Redirect("home.aspx", false); overload i have
> the "Authentication failed" error. So how can i redirect from a webmethod?
omer013 - 23 Jan 2008 00:57 GMT
Is there any way to redirect the page on the server side?

> you can not redirect the client from a web method. the redirect only
> redirects the method call. your web method should return the redirect url,
[quoted text clipped - 65 lines]
> > HttpContext.Current.Response.Redirect("home.aspx", false); overload i have
> > the "Authentication failed" error. So how can i redirect from a webmethod?
omer013 - 23 Jan 2008 01:05 GMT
Is there any way to redirect on the server side?

> you can not redirect the client from a web method. the redirect only
> redirects the method call. your web method should return the redirect url,
[quoted text clipped - 65 lines]
> > HttpContext.Current.Response.Redirect("home.aspx", false); overload i have
> > the "Authentication failed" error. So how can i redirect from a webmethod?
Ven - 18 Mar 2008 10:10 GMT
Hi,

Have you got the answer ? am also in same place, i want to redirect to
another from webmethod...

> Is there any way to redirect on the server side?
>
[quoted text clipped - 67 lines]
> > > HttpContext.Current.Response.Redirect("home.aspx", false); overload i have
> > > the "Authentication failed" error. So how can i redirect from a webmethod?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.