首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >asp.net-mvc和webforms共存

asp.net-mvc和webforms共存
EN

Stack Overflow用户
提问于 2009-12-15 00:35:17
回答 3查看 846关注 0票数 1

我知道我以前问过这个问题,我知道有大量的资源来描述这种技术,但我无法在我的一生中解决这个问题。

我首先创建了一个简单的WebForms应用程序。

然后我添加了视图和控制器文件夹。然后,我将主文件夹和共享文件夹添加到视图中,并添加了一个Index.aspx和一个site.master文件。

我创建了HomeController.cs文件。

然后,我对web.config进行了更改,并将web.config添加到视图文件夹中。

然后,我对global.asax页面进行了更改。

整件事编译,路由似乎得到注册,但我只是不能打开主页/索引页面。

我总是得到"HTTP错误404 -找不到“

有人真的做到了吗?哦,我们这里用的是IIS6。

代码在下面

全局

代码语言:javascript
复制
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

代码语言:javascript
复制
<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>

家庭控制器

代码语言:javascript
复制
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();
    }
}

家景

代码语言:javascript
复制
<%@ 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>
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2009-12-18 00:07:10

事实证明,网站需要是一个web应用程序。

我还需要将以下内容添加到web.config中;

代码语言:javascript
复制
<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所有的努力帮助。

票数 1
EN

Stack Overflow用户

发布于 2009-12-15 01:47:11

我会走另一条路,创建一个MVC应用程序,然后添加您需要的webforms。由于默认的MVC应用程序已经为您设置了所有必要的部分,所以要简单得多。

您需要创建一个独立的文件夹,您的webforms将在其中居住。然后,您可以根据需要将文件夹包含/排除在路由引擎中。

票数 1
EN

Stack Overflow用户

发布于 2009-12-15 01:26:19

你设置通配符映射了吗?

http://haacked.com/archive/2008/11/26/asp.net-mvc-on-iis-6-walkthrough.aspx

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1904524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档