I've been doing some research into how I can add data based on the login credentials. as an example scenario lets say I want a user to login to the application and then based on there login, add there hours they have done for that day, so like a timesheet application.
when using the insert call method in (_customnameDataService.cs) you can add in a username by associating a field within a table like below:
entity.Username = Application.User.Name
so if this is possible there must be a way of calling this in JavaScript when logging in so any help or pointers would be great help. Adding a DataItem and displaying the username would be most preferable. (using edit render code) then from this I can pass it through the hierarchy and display only the information associated with the logged in user.
follow these steps to achieve the above question:
function CallGetUserName(operation) { $.ajax({ type: 'post', data: {}, url: '../web/GetUserName.ashx', success: operation.code(function AjaxSuccess(AjaxResult) { operation.complete(AjaxResult); }) }); }
myapp.BrowseUsers.username_postRender = function (element, contentItem) {
msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) { if (PromiseResult == 'TestUser' || PromiseResult == 'administrator') { } else { contentItem.value = PromiseResult; } });
};
What is actually happening?
The function is calling the GetUserName.ashx file, which in turn retrieves the current user logged in. (from the aspnet_Users table which is automatically created) I have used a foreign key to associated my table (tbl_Users) and aspnet_Users together.
in the debug or release environment if you were to add a data item (string) and display this information, it would return ("TestUser")
myapp.BrowseUsers.displayUsername_postRender = function (element, contentItem) {
msls.promiseOperation(CallGetUserName).then(function PromiseSuccess(PromiseResult) { element.innerText = PromiseResult; }); };