簡體   English   中英

如果我嘗試從Page.aspx重定向頁面,則會出現問題

[英]Problem if I try to redirect page from Page.aspx

我正在構建一個ASP.NET應用程序。

這有此頁面Pagina.aspx,這是代碼:

namespace AnalisiHRVElaborazioni
{
    public partial class Pagina : System.Web.UI.Page
    {
        OmniaCareRehabDemProductionEntities dbTool = new OmniaCareRehabDemProductionEntities();

        static HttpClient client = new HttpClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            int? locateInput = null;
            int? replaceMethod = null;
            int? replaceInput = null;
            int? detrendMethod = null;
            int? waveletLevels = null;
            int? smoothMethod = null;
            int? smoothSpan = null;
            double? smoothDegree = null;
            int? polyOrder = null;
            int? meanCorrection = null;
            int? resampleRate = null;
            int? lambda = null;
            int? sdnni = null;
            int? pnnx = null;
            int? tFWindow = null;
            int? tFOverlap = null;
            int? m = null;
            double? r = null;
            int? n1 = null;
            int? n2 = null;
            int? breakpoint = null;
            double vlfMin;
            double vlfMax;
            double lfMin;
            double lfMax;
            double hfMin;
            double hfMax;

            int? arOptionOrder = null;
            int? winWith = null;
            int? winOverlap = null;
            int? pointPSD = null;
            int? interpolationRate = null;

            String idSlot = Request.QueryString["idSlot"];
            if (!String.IsNullOrEmpty(idSlot))
            {
                Response.Redirect("Home/TimeDomain");
            }
            else
            {
                String charMethod = Request.QueryString["charMethod"];
                String _locateInput = Request.QueryString["locateInput"];

                String _replaceMethod = Request.QueryString["replaceMethod"];
                String _replaceInput = Request.QueryString["replaceInput"];
                String _detrendMethod = Request.QueryString["detrendMethod"];
                String _waveletLevels = Request.QueryString["waveletLevels"];

                if (!String.IsNullOrEmpty(_locateInput))
                    locateInput = int.Parse(_locateInput);

                if (!String.IsNullOrEmpty(_replaceMethod))
                    replaceMethod = int.Parse(_replaceMethod);

                if (!String.IsNullOrEmpty(_replaceInput))
                    replaceInput = int.Parse(_replaceInput);

                if (!String.IsNullOrEmpty(_detrendMethod))
                    detrendMethod = int.Parse(_detrendMethod);

                if (!String.IsNullOrEmpty(_waveletLevels))
                    waveletLevels = int.Parse(_waveletLevels);


                RR rr = new RR();
                RR.Filter filter = new RR.Filter();
                filter.locateInput = locateInput;
                filter.replaceMethod = replaceMethod;
                filter.replaceInput = replaceInput;
                filter.detrendMethod = detrendMethod;
                filter.waveletLevels = waveletLevels;

                //recupero l'RR
                rr.rr = getRR(10);
                rr.filter = filter;

                var json = new JavaScriptSerializer().Serialize(rr);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:28302/api/parse");
                request.Method = "POST";
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(json);

                request.ContentLength = byteArray.Length;
                request.ContentType = @"application/json";

                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }
                long length = 0;
                try
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                    {
                        length = response.ContentLength;
                        Stream stream = response.GetResponseStream();
                        StreamReader sr = new StreamReader(stream);
                        var jsonObject = new JavaScriptSerializer().DeserializeObject(sr.ReadToEnd());
                        //ottenuto l oggetto posso mettere tutto in sessione
                        Session["jsonElaborato"] = jsonObject;
                        Session["loadJson"] = true;
                        Response.Redirect("Home/TimeDomain/?idSlot=null");
                    }
                }
                catch (WebException ex)
                {
                    // Log exception and throw as for GET example above
                }                 
            }
        }   

        [NonAction]
        public decimal?[] getRR(int idSlot)
        {
            /**
             * qui devo recuperare il codice per recuperare le informazioni real time dal database
             * */
            return (from r in dbTool.AA_V_RRSlotXRR
                    where r.IdSlotRR == idSlot
                    select r.y).ToArray();

        }  
    }
}

我用以下網址調用此頁面:

http://localhost:12636/Pagina.aspx/?charMethod="percent"&locateInput=900.....

如果我嘗試調用此頁面。 我可以執行所有代碼並調用Web服務。

然后在執行這些代碼行之后

Session["jsonElaborato"] = jsonObject;
Session["loadJson"] = true;
Response.Redirect("Home/TimeDomain/?idSlot=null");

我希望系統在“ Home/TimeDomain頁面上重定向瀏覽器。 但是不幸的是,該頁面總是在Pagina.aspx頁面中重定向。 為什么呢

請嘗試以下方法:

try
{

  // your coding here

}
catch(){}
 Response.Redirect("Home/TimeDomain/?idSlot=null");

並非全部干凈,但可能您需要類似

Response.Redirect("~/TimeDomain/?idSlot=null", false)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM