请按照以下步骤解决上述问题:
- 谷歌 GetUserName.ashx 以获取此文件的代码以添加到您的 Lightswitch HTML 项目中。
- 将以下函数复制到 javascript 文件中(在我的情况下,我的用户的浏览屏幕)
function CallGetUserName(operation) {
$.ajax({
type: 'post',
data: {},
url: '../web/GetUserName.ashx',
success: operation.code(function AjaxSuccess(AjaxResult) {
operation.complete(AjaxResult);
})
});
}
- 对于可以登录和访问 Lightswitch 应用程序的用户,用户信息必须存储在某个地方,在我的例子中是“ tbl_Users ”。该表有一行名为username。使用下面的代码,管理员或层次结构中的高层人员可以访问所有用户,并且表中引用的特定用户也可以访问自己。
myapp.BrowseUsers.username_postRender = function (element, contentItem) {
msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) {
if (PromiseResult == 'TestUser' || PromiseResult == 'administrator') {
} else {
contentItem.value = PromiseResult;
}
});
};
实际发生了什么?
该函数正在调用 GetUserName.ashx 文件,该文件反过来检索当前登录的用户。(从自动创建的aspnet_Users表中)我使用外键将我的表(tbl_Users)和aspnet_Users关联在一起。
在调试或发布环境中,如果您要添加数据项(字符串)并显示此信息,它将返回(“ TestUser ”)
myapp.BrowseUsers.displayUsername_postRender = function (element, contentItem) {
msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult)
{
element.innerText = PromiseResult;
}); };