mardi 16 juillet 2019

After Login Webform1 driectly loads catch block when hosting on server

I am trying to make a website for travel details. Problem is when when I am trying the code locally i.e. on my system it works perfectly but when I am hosting it on IIS, after clicking on sign in button on login page the webform1.aspx catch block code is executed directly i.e. it returns back to login page.

Login page code:

<div class="form-label-group">
    <input type="text" runat ="server" id="inputuser" class="form-control" placeholder= "User Name" required="required" autofocus="autofocus"/>
    <label for="inputEmail">User Name</label>     
  </div>
 <div class="form-label-group">
<input type="password" runat ="server" id="inputPassword" class="form-control" placeholder="Password" required="required" />
    <label for="inputPassword">Password</label>
  </div>
    <asp:Button Text ="Sign IN" runat ="server" ID="login" OnClick ="Button1_Click1" type="submit" class="btn btn-lg btn-primary btn-block" /> 

C# Code Login Page:

string email_id = string.Empty;
            string user = "", pass = "", typ = "";
            try
            {
                user = inputuser.Value.ToString();
                pass = inputPassword.Value.ToString();
                //   typ = sel1.Value.ToString();
                string url = "API/verify_user/" + user + "/" + pass; // + typ;
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                Stream receiveStream = myHttpWebResponse.GetResponseStream();
                System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                StreamReader readStream = new StreamReader(receiveStream, encode);
                string chkk = readStream.ReadToEnd();
                myHttpWebResponse.Close();
                readStream.Close();
                chkk = chkk.Replace(@"\", "");
                int lgt = chkk.Length;
                chkk = chkk.Substring(1, lgt - 2);
                var jso = new JavaScriptSerializer();
                var JSONObj = jso.Deserialize<List<Dictionary<string, string>>>(chkk);
                int len = JSONObj.Count();
                string sta = string.Empty;

                if (len > 0)
                {
                    sta = JSONObj[0]["status"].ToString();
                    if (sta == "1")
                    {
                        email_id = JSONObj[0]["email_id"].ToString();
                        Response.Redirect("Webform1.aspx?name=" + email_id, false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else if (sta == "0")
                    {
                        Response.Write("<script>alert('Email ID wrong or Does not Exist. Please check!');</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('" + sta + "');</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Email ID wrong or Does not Exist. Please check!');</script>");
                }

            }
            catch (Exception ie)
            {
                Response.Write("<script>alert('" + ie.Message.ToString() + "');</script>");
            }
        }

Webform1 code:

try
            {
                string name = Request.QueryString["name"];
                // name = name.Replace(".", " ");
                string url = "API/emp_data/" + name;
                HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
                Stream receiveStream = myHttpWebResponse.GetResponseStream();
                System.Text.Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
                StreamReader readStream = new StreamReader(receiveStream, encode);
                string chkk = readStream.ReadToEnd();
                myHttpWebResponse.Close();
                readStream.Close();

                chkk = chkk.Replace(@"\", "");
                int lgt = chkk.Length;
                chkk = chkk.Substring(1, lgt - 2);

                var jso = new JavaScriptSerializer();
                var JSONObj = jso.Deserialize<List<Dictionary<string, string>>>(chkk);
                int len = JSONObj.Count();
                Response.Write("<script>alert('"+ len + "');</script>");
                if (len > 0) { 
                emp_name.Value = JSONObj[0]["emp_name"].ToString();
                emp_num.Value = JSONObj[0]["emp_no"].ToString();
                desig.Value = JSONObj[0]["designation"].ToString();
                loc.Value = JSONObj[0]["emp_location"].ToString();
                rpg_mgr.Value = JSONObj[0]["reporting_manager"].ToString();
                }
                else
                {
                    Response.Write("<script>alert('Error while processing! Refresh Page...');</script>");
                    Response.Redirect("Login.aspx", true);
                }

            }
            catch (WebException ec)
            {
                form1.Visible = false;
                Response.Write("<script>alert('Error while processing! Refresh Page...');</script>");
                Response.Redirect("Login.aspx", true);
            }         

No idea why try code is not working. It should move to Webform1.aspx where it will show the employee travel details.




Aucun commentaire:

Enregistrer un commentaire