Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How can i redirect from a webmethod?

Reply
Thread Tools

How can i redirect from a webmethod?

 
 
omer013
Guest
Posts: n/a
 
      01-21-2008
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?


 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      01-21-2008
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)


"omer013" wrote:

> 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?
>
>

 
Reply With Quote
 
 
 
 
omer013
Guest
Posts: n/a
 
      01-23-2008
Is there any way to redirect the page on the server side?

"bruce barker" wrote:

> 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)
>
>
> "omer013" wrote:
>
> > 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?
> >
> >

 
Reply With Quote
 
omer013
Guest
Posts: n/a
 
      01-23-2008
Is there any way to redirect on the server side?

"bruce barker" wrote:

> 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)
>
>
> "omer013" wrote:
>
> > 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?
> >
> >

 
Reply With Quote
 
Ven
Guest
Posts: n/a
 
      03-18-2008
Hi,

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

"omer013" wrote:

> Is there any way to redirect on the server side?
>
> "bruce barker" wrote:
>
> > 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)
> >
> >
> > "omer013" wrote:
> >
> > > 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?
> > >
> > >

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Response.redirect does not redirect from .aspx page =?Utf-8?B?VHJveQ==?= ASP .Net 3 10-15-2008 09:07 PM
when I click on "Save as", can I redirect to particular dir, can I control from html code? GS HTML 3 11-14-2006 07:33 PM
Redirect to secure FTP site via response.redirect Ron Howard ASP General 2 08-11-2004 07:40 PM
Basic Q - Response.Redirect, all redirect to first Response.Redirect statement Sal ASP .Net Web Controls 1 05-15-2004 03:46 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57