【发布时间】:2017-12-11 22:15:23
【问题描述】:
我有一个 ASP.NET Web 应用程序,在该应用程序中,我根据用户单击的菜单从站点呈现不同的画面仪表板。我有多个菜单,每个菜单都绑定到一个画面 URL。
已实施 Tableau 可信身份验证以从 tableau 服务器获取可信票证。检索到票证后,我会将票证与每个菜单的服务器名称一起附加到仪表板 URL。
受信任的票务模块工作正常,可视化正在我的 Web 应用程序中呈现。但是,我经常收到“无法找到未过期的票证”错误消息。
在检查此错误时,这是由于工单调用重复造成的。
我就此联系了支持人员并得到了回复,我可以在我的受信任票务期间添加 client_ip。
我找不到任何与在可信票务中添加 client_ip 相关的代码文章。
以下是我信任的票证代码。
public class TableauTicket
{
public string getTableauTicket(string tabserver, string sUsername)
{
try
{
ASCIIEncoding enc = new ASCIIEncoding();
string postData = string.Empty;
string resString = string.Empty;
postData = "username=" + sUsername + "";
// FEATURE 816 END - Custom Visualization - KV
if (postData != string.Empty)
{
byte[] data = enc.GetBytes(postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(tabserver + "/trusted");
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
req.ContentLength = data.Length;
Stream outStream = req.GetRequestStream();
outStream.Write(data, 0, data.Length);
outStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
StreamReader inStream = new StreamReader(stream: res.GetResponseStream(), encoding: enc);
resString = inStream.ReadToEnd();
inStream.Close();
return resString;
}
else
{
resString = "User not authorised";
return resString;
}
}
catch (Exception ex)
{
string resString = "User not authorised";
return resString;
string strTrailDesc = "Exception in tableau ticket - " + ex.Message;
}
}
public int Double(int i)
{
return i * 2;
}
}
谁能告诉我如何在受信任的票务代码中传递 client_ip?
此外,每个用户的客户端 IP 都会发生变化,以及如何在受信任的票证中进行处理?
更新
我已经使用 tableau 提供的关于如何在 SharePoint 中嵌入视图的源代码解决了这个问题。
以下代码可以帮助遇到同样问题的用户。
string GetTableauTicket(string tabserver, string tabuser, ref string errMsg)
{
ASCIIEncoding enc = new ASCIIEncoding();
// the client_ip parameter isn't necessary to send in the POST unless you have
// wgserver.extended_trusted_ip_checking enabled (it's disabled by default)
string postData = "username=" + tabuser + "&client_ip=" + Page.Request.UserHostAddress;
byte[] data = enc.GetBytes(postData);
try
{
string http = _tabssl ? "https://" : "http://";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(http + tabserver + "/trusted");
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();
return "-1";
}
}
【问题讨论】:
标签: asp.net tableau-api