[RESOLVED]Asp Mvc 4 action was not found and some others also not found

I’m working on a project in ASP MVC 4. it was working good. but few days ago i had very strange problem. i have controller "Dashboard" when i call its index as ~/Dashboard/index it works fine but if i call it as ~/Dashboard i got HTTP 404 not found error.

routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "UI.Web.Controllers" }
            );

i even add a route config for Dashboard controller but it doesn’t work

routes.MapRoute(
            name: "Dashboard",
            url: "Dashboard/{action}/{id}",
            defaults: new { controller = "Dashboard", action = "Index", id = UrlParameter.Optional },
            namespaces: new string[] { "UI.Web.Controllers" }
            );

Same kind of problem in some controllers in my Admin area (some are working fine and some gives HTTP 404 not found error. My Area route config is:

context.MapRoute(
                "DMS_Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { controller = "Contact", action = "Index", id = UrlParameter.Optional },
                new string[] { "UI.Web.Areas.Admin.Controllers" }
            );

in admin area some controller’s index action not working and one controller having AddEdit action that also not working.

public ActionResult AddEdit(string id)
        {
            var user = new Models.RegisterModel();//string.IsNullOrWhiteSpace(id) ? new Models.RegisterModel() : Membership.GetUser(id);

            if (!string.IsNullOrWhiteSpace(id))
            {
                var obj = Membership.GetUser(id);
                if (obj != null)
                {
                    user.Email = obj.Email;
                    user.UserName = obj.UserName;
                }
            }

            ViewBag.PageTitle = string.IsNullOrWhiteSpace(id) ? "Add User" : "Edit User";
            ViewBag.IsAjax = Request.IsAjaxRequest();
            if (Request.IsAjaxRequest())
                return PartialView("~/Areas/Admin/Views/Users/AddEditPartial.cshtml", user);
            return View("~/Areas/Admin/Views/Users/AddEdit.cshtml", user);
        }

in AddEdit action if i call it as ~/Admin/User/AddEdit/a it works but if i call it as ~/Admin/User/AddEdit it also gives HTTP 404 not found error.

is this behaviour due to some framework update issue or code problem? any idea…. i don’t think that this is coding issue because same code was working before……

Now i was about finish my project and in last stage i stuck here.

unfortunately my code is working fine on hosting server. but i need to add new functionality so i need this to work on my development machine also. 

Hi,

According to your description, it is not working in your development machine. I would like to know whether it is working in the VS with IIS express.

Could you reproduce that issue in a new project? If that is the case, you may share the project on the OneDrive.

Please check Modules in the IIS whether there is the UrlRoutingModule. (UrlRoutingModel-4.0 in my machine)

You could try to add runAllManagedModulesForAllRequests attribute of modules in
system.webServer section.

For example:

<modules>
      <remove name="UrlRoutingModule-4.0" />
      <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
    </modules>

Best Regards

Starain

Leave a Reply