从一个正常的.aspx页面中推出一个ASP MVC项目 [英] Launch an ASP MVC project from a normal .aspx page

查看:157
本文介绍了从一个正常的.aspx页面中推出一个ASP MVC项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的ASP.NET网站上.NET 4.5上运行。我需要整合一个ASP MVC 4项目(这是它自己的功能完整的Web应用程序)到其中,因此,当用户浏览到某个页面时,ASP MVC应用程序在页面内推出 - 仿佛它是在 IFRAME

I have an existing ASP.NET web site running on .NET 4.5. I need to integrate an ASP MVC 4 project (which is its own fully-functional web application) into it so that when the user navigates to a certain page, the ASP MVC application is launched within the page - almost as if it were in an iframe.

在主要的解决办法,我可以同时设置为启动项目,但是这显然不是我所期待的。有人能指出我在如何做到这一点的方向?我从来没有使用WCF,但就是这个东西,它可以用来做什么?感谢您的任何事!

In the main solution I can set both as startup projects, but this is obviously not what I am looking for. Can someone point me in the direction of how to do this? I have never used WCF before, but is this something that it could be used for? Thanks for anything!

推荐答案

您可以创建一个混合web表单 - MVC应用程序

You can create a hybrid webforms - MVC application.

要做到这一点,你需要:

To do this you need to:


  • 从一个新的MVC项目的web.config文件复制MVC配置您的WebForms应用程序的web.config

  • 创建标准MVC 4个文件夹(至少查看,控制器)

  • 引用所需的程序集

  • 复制里面从MVC项目到项目的WebForms视图文件夹视图中的web.config

  • 改变路由配置忽略路线,包括的.aspx /的.ascx,让他们通过网络的形式处理,而不是MVC(这样做也为ashx的,的.asmx,或任何基于假象其他网页形式)

这样,你有一个支持MVC和WebForms的一个ASP.NET应用程序,并使用相同的身份验证,会话等。

This way you have a single ASP.NET application which supports MVC and WebForms, and use the same authentication, session, and so on.

然后就可以使这种集成的:
- 做出完全MVC或完全web表单页面。如果你使用母版页,你需要创建一个母版页Web表单,以及MVC布局(这可能是很难或很容易,这取决于它的内容和设计)
- 做一个web表单页面,并使用AJAX和MVC局部视图整合MVC页

Then you can make this kind of integrations: - make pages that are fully MVC or fully webforms. If you're using master pages, you need to create a master page for web forms, and a layout for MVC (this can be very hard or quite easy, depending on its content and design) - make a webforms page and integrate the MVC pages using AJAX and MVC partial views

APRT frommy意见,这个博客条目将帮助你很多:<一href=\"http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx\"相对=nofollow>集成ASP.NET MVC 3到现有的ASP.NET升级4 Web窗体应用程序

Aprt frommy comments, this blog entry will help you a lot: Integrating ASP.NET MVC 3 into existing upgraded ASP.NET 4 Web Forms applications

顺便说一句,这不是理论上的......我有很多的网页,区,享有一个Web应用程序,它使用了这项技术,它完美的作品。我不得不重做母版页(布局和CSS),这样既样的网页看起来很相似的设计。我很幸运有一个web表单呈现占位符使用SQL XML查询和XSLT菜单,因此重新使用它的MVC布局是绝对容易。你可以做一些类似的在你的母版页和MVC布局(我的意思是手动渲染HTML,并在两个页面使用它,因此,它的工作只有一次)

By the way, this is not theoretical... I have a web application with lots of pages, areas, and views, which uses this technique, and it works flawlessly. I had to redo the design of the master page (layout and CSS) so that both kind of pages look alike. I was lucky enough to have a menu rendered in a webforms placeholder using a SQL XML query and an XSLT, so re-using it in the MVC layout was absolutely easy. You can do something similar to this in your master page and MVC layout (I mean rendering the HTML manually, and using it in both pages, so that it's done only once)

您可能需要一些时间来得到它的工作,但它是值得的。

You can take some time to get it to work, but it's worth the effort.

这篇关于从一个正常的.aspx页面中推出一个ASP MVC项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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