mukesh dutt
mukesh dutt

Reputation: 46

Access one web project from another web project asp.net mvc

Problem

In asp.net mvc i have two mvc application in one solution one is website and second is admin panel. And I I have created one folder that name is administrator inside of website project and paste admin project inside of website project now I want access admin section like way :

http://localhost/website/admin

As like nopcommerce but I'm not getting how nopcommerce configured this thing in their project.

Help me out

Upvotes: 0

Views: 1154

Answers (2)

mukesh dutt
mukesh dutt

Reputation: 46

This tutorial has cleared my confusion that how to configure more then one project in asp.net mvc as area.

http://nileshhirapra.blogspot.no/2012/02/aspnet-mvc-pluggable-application.html?m=1

Upvotes: 0

mike.morain
mike.morain

Reputation: 26

As others have stated, it may be best to use ares in order to simplify the project, but if you want to keep them separated, I think the problem you are having is updating your routing.

By default, MVC applications have the following routing config (found in the Globals.asax.cs file):

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

What you will need to do is look at the controller you're trying to wire up, and put in a route for that controller. For the sake of an example, I will assume your controller is called "AdminController":

    routes.MapRoute(
       name: "AdminController",
       routeTemplate: "website/admin/{action}",
       defaults: new { controller = "Admin", action = "Index"}
    );

    routes.MapRoute(
        "Default",                                              // Route name
        "{controller}/{action}/{id}",                           // URL with parameters
        new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
    );

This example shows you how to map the desired route -- http://localhost/website/admin -- to the "Index" action on the "AdminController" object.

For more in-depth ASP.Net routing examples, you can look at the documentation here

Update: After looking at the example library in question (NopCommerce), it would appear they are using an explicit area registration. This is found in 'src/Presentation/Administration/AdminAreaRegistration.cs' :

using System.Web.Mvc;

namespace Nop.Admin
{
    public class AdminAreaRegistration : AreaRegistration
    {
        public override string AreaName
        {
            get
            {
                return "Admin";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context)
        {
            context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", area = "Admin", id = "" },
                new[] { "Nop.Admin.Controllers" }
            );
        }
    }
}

Hopefully this gives you a better idea of how this is done.

Upvotes: 1

Related Questions