I'm working on MVC3 UserManagement and on local (VS2010) all seems to be working fine but on IIS(7.5) it just won't show any response to JSON post.
Table for users generator:
this.init = function (tableSelector) {
// get user table
userTable = $(tableSelector);
// fill the user table with all
$.post('/{controllerName}/GetAllUsers', {}, function (users) {
// add users to table
for (var i in users) {
appendUser(users[i]);
}
//initialize table sorter and pager
userTable.tablesorter({ widthFixed: true, widgets: ['zebra'] }).tablesorterPager({ container: $("#pager"), positionFixed: false, removeRows: false });
// bind user action link event handlers for all rows
userTable.on('click', '.delete-user', deleteUser);
userTable.on("click", ".unlock-user", unlockUser);
userTable.on("click", ".manage-roles", manageRoles);
});
}
Routes register method:
public static void RegisterMe()
{
var routes = RouteTable.Routes;
using (routes.GetWriteLock())
{
routes.MapRoute("SimpleUserManagementRoute",
"SimpleUserManagement/{action}",
new { controller = "UserManagement", action = "GetAllUsers" },
new string[] { "SimpleMvcUserManagement" });
}
}
Controller part:
public IUserAccountService _accountService { get; set; }
public JsonResult GetAllUsers()
{
var users = _accountService.GetAllUsers();
var result = from MembershipUser user in users
select CreateJsonUserObject(user);
return Json(result);
}
Now by looking around StackOverflow, I've found that issue lies with strong-coded URL. Reference: MVC 3 JSON call not working in IIS
And i've tried replacing my URLs with those mentioned in the reference, but of course it didn't work since I don't know where/how to stringify
my url :( , also not sure if that solution would even work with this.
Please help. TY!
Has your IIS been configured with a virtual directory? What happens if you put /{controllerName}/GetAllUsers into your browser? Do you get a response or a 404?
The URL you are passing to the $.post
is wrong.
It should be either,
$.post("/Register/GetAllUsers", ...)
// assuming the controller is RegisterController
or
$.post('@Url.Action("GetAllUsers", "Register")',..