0

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!

3
  • what's the error? not found 400? internal error 500? Commented Jul 13, 2012 at 15:30
  • Usually you just post directly to the route, you don't need to include the controller. Commented Jul 13, 2012 at 15:31
  • You can stringify using Douglas Crockfords JSON.js available here: github.com/douglascrockford/JSON-js Commented Jul 13, 2012 at 15:33

2 Answers 2

0

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?

Sign up to request clarification or add additional context in comments.

3 Comments

I get 404. But when I use /{controllerName}/GetAllUsers it does indeed show it like /UserManagement/GetAllUsers just it's not showing any return data... Only 404 on response
If you can hit the breakpoint you can step through and see var users is empty?
I don't have dev environment on server, just in local, and on local everything works... Meaning, nothing to debug with on server.
0

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")',.. 

1 Comment

My Urls are fine since they work on local, I've tried with Url Helpers , but same thing happens, on server error 404.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.