This may be by design or it may be something I am or am not doing.
I have an MVC 4 application that the AccountController is using the Authorize attribute on. When the user is on the Login page, there is an Teller Issue Date that is used once they are logged in. I am trying to capture the change event on the Name field, which is working fine, and firing a Jquery function to get the Issue Date.
Here is the JQuery Ajax function:
function update_issue_date() {
var userName = $('#UserName').val();
$.ajax({
type: 'GET',
url: '/Account/GetIssueDate',
async: true,
data:
{
userName: userName
},
success: function(data) {
$('#IssueDate').val(__format_date_for(new Date(data.issueDate)));
}
});
In the AccountController I have the folowing Action:
[AllowAnonymous]
public ActionResult GetIssueDate(string userName)
{
var issueDate = DateTime.Now.Date;
if (userName.Length > 0)
{
var user = userRepo.GetUser(userName);
//var user = user_repository.get_all().FirstOrDefault(x => x.user_name == userName);
var currentDate = DateTime.Now.Date;
issueDate = (user == null || user.IssueDate < currentDate) ? currentDate : user.IssueDate;
}
return Json(new { issueDate = issueDate.ToShortDateString() }, JsonRequestBehavior.AllowGet);
}
Here is what happens, if I have the Authorize stuff disabled in the web.config, then this function works as is should returning the proper Issue Date. But, if I have the Authorize things enabled, then the GetIssueDate Action does not seem to be fired. And I get the HTML for the Login Page.
I figure that even though I have the [AllowAnonymous] attribute on this Action, the application seems to ignore this when called from the Jquery function, and does not allow it to fire.
Is there a way around this, or perhaps another way to do what I am trying to do?
Thanks.