简体   繁体   中英

Problem if I try to redirect page from Page.aspx

I'm building an ASP.NET application.

This have this page Pagina.aspx, this is the code:

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();

        }  
    }
}

I call this page with this url:

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

If I try to call this page. I can execute all code and call a web service.

Then after execute these line of code

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

I expect that the system redirect the browser at Home/TimeDomain page. But unfortunately the page is redirect always in Pagina.aspx page. Why ?

Please try this:

try
{

  // your coding here

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

并非全部干净,但可能您需要类似

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM