I have the plan to code new content of our old asp.net website with MVC.
User want no discontinuity between old and new sites, so I have to use same solution and make page from old and new "Way" speak each other.
I follow this topic
but when I try to open page - I get "Error HTTP 404.0 - Not Found" exception.
What I do is:
- Add MVC to my web project with Nuget
- Edit
web.config
section to this
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="System.Data.Services.Client, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/> <add assembly="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/> <add assembly="System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
Edit my global.asax to this:
public class Global : System.Web.HttpApplication { public void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); } public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.aspx/{*pathInfo}"); routes.MapRoute( "Home", // Route name "home/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults ); } protected void Application_Start() { RegisterGlobalFilters(GlobalFilters.Filters); RegisterRoutes(RouteTable.Routes); } } void Application_Start(object sender, EventArgs e) { ... my old code } void Application_End(object sender, EventArgs e) { ... my old code } void Application_Error(object sender, EventArgs e) { ... my old code } void Session_Start(object sender, EventArgs e) { ... my old code } void Session_End(object sender, EventArgs e) { ... my old code } protected void Application_BeginRequest(Object sender, EventArgs e) { ... my old code }
Create
HomeController
inAppCode
folder:using System.Web.Mvc; public partial class HomeController : Controller { protected override void Execute(System.Web.Routing.RequestContext requestContext) { base.Execute(requestContext); } public ActionResult Index() { var r = new ContentResult(); r.Content = "Hello world"; return r; } }
This is what I get:
I have also tried this way but got same error.
I read this but it suggests migrating entire site to Web Application and I am afraid to do that...