我知道我以前问过这个问题,我知道有大量的资源来描述这种技术,但我无法在我的一生中解决这个问题。
我首先创建了一个简单的WebForms应用程序。
然后我添加了视图和控制器文件夹。然后,我将主文件夹和共享文件夹添加到视图中,并添加了一个Index.aspx和一个site.master文件。
我创建了HomeController.cs文件。
然后,我对web.config进行了更改,并将web.config添加到视图文件夹中。
然后,我对global.asax页面进行了更改。
整件事编译,路由似乎得到注册,但我只是不能打开主页/索引页面。
我总是得到"HTTP错误404 -找不到“
有人真的做到了吗?哦,我们这里用的是IIS6。
代码在下面
全局
public static void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}.mvc/{action}/{id}", // URL with parameters
new { action = "Index", id = "" } // Parameter defaults
);
routes.MapRoute(
"Root",
"",
new { controller = "Home", action = "Index", id = "" }
);
}Web.Config
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Abstractions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
<namespaces>
<add namespace="System.Web.Mvc"/>
<add namespace="System.Web.Mvc.Html"/>
<add namespace="System.Web.Routing"/>
<add namespace="System.Web.Mvc.Ajax"/>
<add namespace="System.Linq"/>
<add namespace="System.Collections.Generic"/>
</namespaces>
</pages>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>家庭控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
[HandleError]
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult About()
{
return View();
}
}家景
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MVCSite.master" Inherits="System.Web.Mvc.ViewPage"%>
<script runat="server">
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
MVC Home Page
<%= Html.TextBox("txtTest") %>
<%= Html.ActionLink("About Page", "About") %>
</asp:Content>发布于 2009-12-18 00:07:10
事实证明,网站需要是一个web应用程序。
我还需要将以下内容添加到web.config中;
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing"/>感谢和+1所有的努力帮助。
发布于 2009-12-15 01:47:11
我会走另一条路,创建一个MVC应用程序,然后添加您需要的webforms。由于默认的MVC应用程序已经为您设置了所有必要的部分,所以要简单得多。
您需要创建一个独立的文件夹,您的webforms将在其中居住。然后,您可以根据需要将文件夹包含/排除在路由引擎中。
发布于 2009-12-15 01:26:19
你设置通配符映射了吗?
http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx
https://stackoverflow.com/questions/1904524
复制相似问题