Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to integrate mvc4 in asp.net 4.0+webform programs

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces you how to use asp.net 4.0+webform program to integrate mvc4, the content is very detailed, interested friends can refer to, hope to be helpful to you.

1. Create a new packages.config file with necessary assemblies in it

2. Return the original package in the corresponding web project

Update-package-projectname 'web'-reinstall

3. Create a new App_Start directory and add the configuration code corresponding to mvc.

BundleConfig.cs is the configuration code for static file compression. The reference code is as follows:

For more information about Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725 public static void RegisterBundles (BundleCollection bundles) {bundles.Add (new ScriptBundle ("~ / bundles/jquery"). Include ("~ / Scripts/jquery- {version} .js"); bundles.Add (new ScriptBundle ("~ / bundles/common"). Include ("~ / js/common*")) Bundles.Add (new ScriptBundle ("~ / bundles/echarts"). Include ("~ / js/echarts.common*"); bundles.Add (new ScriptBundle ("~ / bundles/mustache"). Include ("~ / js/mustache*")); bundles.Add (new ScriptBundle ("~ / bundles/blockUI"). Include ("~ / js/jquery.blockUI*"); bundles.Add (new StyleBundle ("~ / Content/oa/css"). Include ("~ / css/oa/style.css")) / / BundleTable.EnableOptimizations = true;}}

RouteConfig.cs configures the code for routing. Resources related to web form should ignore route filtering here.

Public class RouteConfig {public static void RegisterRoutes (RouteCollection routes) {routes.IgnoreRoute ("{resource} .axd / {* pathInfo}"); / / routes.IgnoreRoute ("{resource} .aspx / {* pathInfo}"); / / routes.IgnoreRoute ("{resource} .ashx / {* pathInfo}"); routes.IgnoreRoute ("{resource} .aspx / {* pathInfo}"); routes.IgnoreRoute ("{handler} .ashx / {* pathInfo}") Routes.IgnoreRoute ("Handlers/ {handler} .aspx / {* pathInfo}"); routes.IgnoreRoute ("ajaxpro/prototype.ashx"); routes.IgnoreRoute ("ajaxpro/core.ashx"); routes.IgnoreRoute ("ajaxpro/converter.ashx"); routes.IgnoreRoute ("ajaxpro/ {resource} .ashx"); routes.IgnoreRoute ("{resource} .asmx / {* pathInfo}") Routes.MapRoute (name: "Default", url: "{controller} / {action} / {id}", defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional});}}

WebApiConfig.cs is the routing configuration for WebApi. Refer to the code:

Public static class WebApiConfig {public static void Register (HttpConfiguration config) {config.Routes.MapHttpRoute (name: "DefaultApi", routeTemplate: "api/ {controller} / {id}", defaults: new {id = RouteParameter.Optional});}}

4. Add the following code to the Application_Start event in the Global file to make the program startup MVC configuration effective

AreaRegistration.RegisterAllAreas (); GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add (new QueryStringMapping ("json", "true", "application/json")); WebApiConfig.Register (GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters (GlobalFilters.Filters); RouteConfig.RegisterRoutes (RouteTable.Routes); BundleConfig.RegisterBundles (BundleTable.Bundles); GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear ()

5. Create a new Controllers folder and add a controller class to it, for example

Public class DocRecController: Controller {public ActionResult Index () {ViewBag.UserName = "wilson.fu"; return View ();}}

6. Create a new Views folder with the corresponding view file. If you need to use the template, you need to add the _ ViewStart.cshtml file, such as DocRec/Index.cshtml, as shown below.

@ {Layout = null;} @ ViewBag.UserName

You also need to add a Web.config file under the Views folder for request filtering.

The directory structure is as follows:

After the compilation is completed, visit / docrec/index to see the effect:

On how to use asp.net 4.0+webform programs to integrate mvc4 to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report