我计划用MVC编写旧的asp.net网站的新内容。
用户希望旧网站和新网站之间不会出现任何不连续性,因此我必须使用相同的解决方案,并使新旧“Way”的页面相互说话。
我关注this topic
但是当我尝试打开页面时 - 我收到“错误HTTP 404.0 - 未找到”异常。
我的工作是:
web.config
部分修改为此<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"/>
将我的global.asax编辑为:
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
}
在HomeController
文件夹中创建AppCode
:
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方式,但得到了同样的错误。
我看过this,但它建议将整个网站迁移到网络应用程序,我不敢这样做......