如何从asp.net c中的webservice方法重定向另一个页面# [英] how to redirect another page from webservice method in asp.net c#

查看:106
本文介绍了如何从asp.net c中的webservice方法重定向另一个页面#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,先生,

我必须从当前页面重定向到另一页面。例如我有一个webservice方法,它的工作成功但是当出现任何错误时,我必须重定向我的自定义错误页面。

我当前的页面是City.aspx,我的错误页面是error.aspx i ..



hello sir,
i have to redirect from current page to another page. e.g. i have one webservice method and it's work successfully but when any error is occurs then i have to redirect my custom error page.
my current page is City.aspx and my Error page is error.aspx
i used below code..

[WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
        public static string InsertRequest(string bid
                                            , string cid
                                            , int bookqty
                                            , string rmk)
        {
            try
            {
                  //here is my insert code and it's working...         
            }
            catch (Exception ex)
            {
                HttpContext.Current.Session["errorMsg"] = ex.Message;
                HttpContext.Current.Response.Redirect("error.aspx?pagename=" + System.IO.Path.GetFileNameWithoutExtension(HttpContext.Current.Request.PhysicalPath), false);
                return "fail";
            }





i也使用以下代码..



i also use below code..

HttpContext.Current.Server.Transfer("error.aspx?pagename=" + System.IO.Path.GetFileNameWithoutExtension(HttpContext.Current.Request.PhysicalPath));



但不工作



i也使用以下代码..




But not working

i also use below code..

HttpContext.Current.Response.Write("<script>");
HttpContext.Current.Response.Write("window.location='error.aspx?p=" + pageName + "'");
HttpContext.Current.Response.Write("</script>");





但不工作......





请帮忙...



提前感谢.. !!



But not working....


please help...

thanks in advance..!!

推荐答案

你可以因为你没有完整的回发。您需要返回一个值,然后在JavaScript中查找该值,然后使用javascript中的window.location.href。
You can't because you are not in a full postback. You need to return a value and then look for that value in JavaScript and then use window.location.href from javascript.


这篇关于如何从asp.net c中的webservice方法重定向另一个页面#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆