1 Reply Latest reply on Jan 24, 2014 4:12 AM by Eric McDonald

    Issue With Generate Ticket with tableau Server in Asp.net +C# enviorment

    Prashant Jagdale

      Hi Team,

       

      I am Connect With Tableau server with  asp.net + C# enviromrnt

      generate ticket with Tableau server

       

      My issue is how to generate ticket with tableau server

       

       

      code is below


      Every time I got -1 ticket


      Please suggest ASAP.

       

      I am waiting For Your reply.

       

      protected void Page_Load(object sender, EventArgs e)

          {

            //  ErrTextBx.Text = "";

              string tableauServer = "192.168.20.97:8000"; //"info-tableau-02";

              string viewPath = "views/Wow/911Calls";

              string tableauUser ="Prashant.Jagdale" ;//Context.User.Identity.Name;

              string errMsg = "";

       

       

              string ticket = GetTableauTicket(tableauServer, tableauUser, ref errMsg);

       

       

              Response.Write(ticket.ToString());

              if (ticket == "-1")

              {

                  return;

              }

              string url = "http://" + tableauServer + "/trusted/" + ticket + "/" + viewPath + "?:embed=yes";

            //  tableauViewFrame.Attributes["src"] = url;

          }

       

       

          private string GetTableauTicket(string tabserver, string tabuser, ref string errMsg)

          {

              ASCIIEncoding enc = new ASCIIEncoding();

              string postData = "username=" + tabuser + "&client_ip=" + Page.Request.UserHostAddress;

              byte[] data = enc.GetBytes(postData);

       

       

              try

              {

                  HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://" + tabserver + "/trusted");

               //   HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://" + tabserver );

                  req.Method = "POST";

                  req.ContentType = "application/x-www-form-urlencoded";

                  req.ContentLength = data.Length;

       

       

                  // Write the request

                  Stream outStream = req.GetRequestStream();

                  outStream.Write(data, 0, data.Length);

                  outStream.Close();

       

       

                  // Do the request to get the response

                  HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                  StreamReader inStream = new StreamReader(res.GetResponseStream(), enc);

                  string resString = inStream.ReadToEnd();

                  inStream.Close();

       

       

                  return resString;

              }

              // if anything bad happens, copy the error string out and return a "-1" to indicate failure

              catch (Exception ex)

              {

                  errMsg = ex.ToString();

                 // ErrTextBx.Text = errMsg;

                  return "-1";

              }

          }

       

       

      regards

       

      Prashant.jagdale.