1

我正在尝试在我自己的学习管理系统中使用 .NET TinCan 库。我在我的应用程序中包含了 TinCan 0.0.2 Nuget 包并上传了 GolfExample_TCAPI 测试课程。在本地测试时,GolfExample 课程会在以下 URL 加载:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?

在查看启动文档时,我发现似乎至少需要传入端点、身份验证和参与者,因此我尝试在我的视图模型中使用如下 dll 来执行此操作。

var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");

var actor = new TinCan.Agent();
actor.name = "John Paul Mc Feely";
actor.mbox = "jpmcfeely@hsl-data.com";

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + "/index.html" + "?endpoint=" + lrs.endpoint + "&auth=" + lrs.auth + "&actor=" + actor.ToJSON();  

调试时,我可以看到这为启动窗口创建了 URL,如下所示:

"https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI (1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&auth=Basic anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&actor={\"objectType\":\"Agent\",\"name\":\"John Paul Mc Feely\",\"mbox\":\"jpmcfeely@hsl-data.com\"}"

根据我可以看到的文档,这看起来像是正确的格式,但是当我继续时,窗口会使用以下 URL 启动:

https://127.0.0.1/TINCAN/MYCOMPANY/GolfExample_TCAPI%20(1)/index.html?endpoint=https://cloud.scorm.com/tc/public/&amp;auth=Basic%20anBtY2ZlZWx5QGhzbC1kYXRhLmNvbTpwbGFzbWExMQ==&amp;actor={&quot;objectType&quot;:&quot;Agent&quot;,&quot;name&quot;:&quot;John%20Paul%20Mc%20Feely&quot;,&quot;mbox&quot;:&quot;jpmcfeely@hsl-data.com&quot;}

然后我收到如下警告消息:

[警告] 与学习记录存储通信出现问题。(400 | 声明 3bd49829-dc0b-4daa-a689-71a84c44e6ad 没有分配演员。)

如果有人能在这里看到我做错了什么,将不胜感激。

4

2 回答 2

3

查询字符串参数至少需要进行 URLEncoded。您需要将lrs.endpoint,lrs.authactor.ToJSON()in包装起来HttpUtility.UrlEncode()

using System.Web;

TINCANStartPage = HttpContext.Current.Request.Url.Scheme + 
    "://" + 
    @HttpContext.Current.Request.Url.Host +
    ":" +
    @HttpContext.Current.Request.Url.Port + 
    HttpContext.Current.Request.ApplicationPath + 
    this.Course.BlobURL + 
    "/index.html" + 
    "?endpoint=" + 
    HttpUtility.UrlEncode(lrs.endpoint) + 
    "&auth=" + 
    HttpUtility.UrlEncode(lrs.auth) + 
    "&actor=" + 
    HttpUtility.UrlEncode(actor.ToJSON());

根据警告消息,听起来您正在将其传递给 TinCanJS。我们需要查看该代码以进一步排除故障。实例化TinCan对象的代码需要将其传递url给解析,这似乎正在工作,但可能由于 URL 编码不正确而找不到参与者。

请注意,您通过该响应获得 400 状态这一事实意味着它已成功连接到 LRS,只是请求中发送的内容无效。

于 2014-06-04T12:35:38.873 回答
0

我通过在 ViewModel 上执行以下操作来完成这项工作:

//Initialize the LRS
var lrs = new RemoteLRS("https://cloud.scorm.com/tc/public/", "<username>", "<password>");  

//Initialize the TinCan Actor for Launch String
this.Actor = new TinCan.Agent();
this.Actor.name = this.User.Forename + " " + this.User.Surname;
this.Actor.mbox = this.User.Email;

//Construct the TinCanStartPage
TINCANStartPage = HttpContext.Current.Request.Url.Scheme + "://" + @HttpContext.Current.Request.Url.Host + ":" +
                @HttpContext.Current.Request.Url.Port + HttpContext.Current.Request.ApplicationPath + this.Course.BlobURL + this.LaunchPage;

然后在启动 TinCan 窗口的视图上,我有以下内容:

$(document).ready(function () {

    var myActor = '@Html.Raw(Model.Actor.ToJSON())';        
    var launchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(launchLink, "SCORM", "width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0");

});

function relaunch() {        
    var relaunchLink = '@Model.TINCANStartPage' + '?endpoint=' + '@Model.LRS.endpoint' + '&auth=' + '@Model.LRS.auth' + '&actor=' + myActor;
    window.open(relaunchLink, 'SCORM', 'width=1140,height=760,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
} 
于 2014-06-04T13:22:44.753 回答