混合ASP.NET MVC到ASP.NET的WebForms [英] Mixing ASP.NET MVC into ASP.NET WebForms

查看:201
本文介绍了混合ASP.NET MVC到ASP.NET的WebForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我的路由是忽略任何试图访问我的MVC的网页,只是给了我404。我有一个WebForms的应用设置如下所示:

虚拟目录:事情

所以我通常访问我的网站,像这样:

我的ASP.NET应用程序的WebForms的原始stucture镜像文件系统,所以我有充分的.aspx文件夹,我需要能够使用它们这样。出于某种原因,当我尝试使用MVC路由访问的页面,例如:

我只是得到一个404错误。我已经使用ASP.NET MVC在它自己的,我知道,即使我没有设置我的文件夹正确,我不会得到一个404。我会得到,为什么网页无法被发现和提示的原因其中,文件应该。下面是我的路由信息​​。我在哪里去了?

 公共静态无效的RegisterRoutes(RouteCollection路线)
    {
        routes.IgnoreRoute({}资源个.axd / {*} PATHINFO);
        routes.IgnoreRoute({}资源的.aspx / {*} PATHINFO);
        routes.MapRoute(
           默认,
            //路线名称
           {控制器} / {行动} / {ID}
            // URL带参数
           新{控制器=家,行动=索引,ID =}
            //参数默认
            );
    }保护无效的Application_Start()
        {
            的RegisterRoutes(RouteTable.Routes);
        }


解决方案

你能告诉我你正在运行什么操作系统,这个网站是否是在VS.NET的Web开发服务器或IIS运行?

在路由指导MVC到控制器类的要求,然后具体的操作方法。你有一个名为HomeController的一个叫指数?方法类

假设你有一个控制器,看着这个这个......

 公共类HomeController的:控制器
{
    公众的ActionResult指数()
    {
        返回查看();
    }
}

...那么你提到应该工作的URL。然而,ASP.NET MVC会希望找到在一个文件夹命名视图\\ Home或意见Home控制器\\您的VDIR下共享相关的任何意见。在这种情况下,索引的动作,这将期望找到名为Index.aspx的视图(或的.ascx)。然而,缺少视图通常不会导致404 - 这通常是由控制器引起了不被人发现,操作方法没有被发现,或者在IIS 6的asp.net管道不为VDIR通配符设置为<。 / p>

更新:

你确定你的web.config有MVC的HttpHandler到位(使MVC是在ASP.NET管道)。你应该有这样的事情...

 &LT;添加动词=*路径=。* MVC验证=假TYPE =System.Web.Mvc.MvcHttpHandler,System.Web.Mvc,版本= 1.0.0.0,文化=中性公钥= 31BF3856AD364E35/&GT;

...在你的 HttpHandlers的部分,这...

 &LT;添加名称=UrlRoutingModuleTYPE =System.Web.Routing.UrlRoutingModule,System.Web.Routing,版本= 3.5.0.0,文化=中性公钥= 31BF3856AD364E35 /&GT;

...在web.config中的你的HttpModules部分。

更新2:

基于您的意见我怀疑你没有得到在管道中的ASP.NET MVC code。你应该把你的web.config,并与一个来自刚创建的MVC网站进行比较,寻找丢失的物品配置。我建议以上一对夫妇,但可能有更多的。

For some reason my routing is ignoring any attempt to access my MVC pages and simply giving me 404s. I have a WebForms app set up like the following:

Virtual Directory: thing

So I usually access my site like so:

The original stucture of my ASP.NET WebForms app mirrors the file system so I have folders full of .aspx files and I need to be able to use them like that. For some reason when I try to access a page using the MVC routing such as:

I just get a 404 error. I have used ASP.NET MVC on it's own and I know that even if I didn't set up my folders properly, I wouldn't get a 404. I would get the reasons why the page couldn't be found and hints to where the files should be. Below is my routing info. Where am I going wrong?

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("{resource}.aspx/{*pathInfo}");
        routes.MapRoute(
           "Default",
            // Route name
           "{controller}/{action}/{id}",
            // URL with parameters
           new { controller = "Home", action = "Index", id = "" }
            // Parameter defaults
            );
    }

protected void Application_Start()
        {
            RegisterRoutes(RouteTable.Routes);
        }

解决方案

Can you tell me what OS you're running on and whether this site is running under VS.NET Web Dev server or IIS?

Routing in MVC directs a request to a Controller class and then a specific Action method. Do you have a class named HomeController with a method named Index?

Assuming you had a controller that looked this this...

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

... then the url you mentioned should work. However, ASP.NET MVC will expect to find any views associated with the Home controller in a folder named Views\Home or Views\Shared under your vdir. In this case, for the Index action, it will expect to find a view named Index.aspx (or .ascx). However, a missing view doesn't usually result in 404 - that's usually caused by the controller not being found, the action method not being found, or on IIS 6 the asp.net pipeline not being in the wildcard settings for the vdir.

update:

Are you sure your web.config has the MVC HttpHandler in place (so that MVC is in the ASP.NET pipeline). You should have something like this...

<add verb="*" path="*.mvc" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

... in your httpHandlers section and this...

<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web.Routing, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

... in your 'httpModules' section of web.config.

update 2:

Based upon your comments I suspect you've not got the ASP.NET MVC code in the pipeline. You should take your web.config and compare it with one from a freshly created MVC site and look for the missing config items. I've suggested a couple above, but there might be more.

这篇关于混合ASP.NET MVC到ASP.NET的WebForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆