简体   繁体   English

在同一项目中添加ASP.NET MVC和Web API Web应用程序

[英]Add ASP.NET MVC and Web API Web Application in the same project

I have created a new asp.net (standard) web api project and now I would like to have the front logic (ASP.net MVC) in the same project, I came to know that we can have both client (MVC) and server (Web API) application in the same project. 我创建了一个新的asp.net(标准)Web API项目,现在我想在同一项目中使用前端逻辑(ASP.net MVC),我知道我们可以同时拥有客户端(MVC)和服务器(Web API)应用程序在同一项目中。 I tried to find the step by step process to follow, but I couldn't find any. 我试图找到要遵循的分步过程,但找不到任何东西。 I would really appreciate if someone can provide me steps to follow, as this is the first time I'm building a application from scratch. 如果有人可以提供我要遵循的步骤,我将不胜感激,因为这是我第一次从头开始构建应用程序。 Thanks in advance. 提前致谢。

You could try to create an empty asp.net project and define that this project has the web and api features. 您可以尝试创建一个空的asp.net项目并定义该项目具有Web和api功能。 For sample: 样品:

  1. in Visual Studio 2019, select the asp.net template: 在Visual Studio 2019中,选择asp.net模板:

在此处输入图片说明

  1. Define the name of the project 定义项目名称

在此处输入图片说明

  1. Select the Empty and check the options, MVC and Web Api 选择Empty并检查选项, MVCWeb Api

在此处输入图片说明

In the App_Start folder you will see two files. App_Start文件夹中,您将看到两个文件。 The RouteConfig.cs file define the routes for the ASP.NET MVC Web App. RouteConfig.cs文件定义ASP.NET MVC Web应用程序的路由。 The WebApiConfig.cs file define the routes for the ASP.NET Web Api application. WebApiConfig.cs文件定义ASP.NET Web Api应用程序的路由。

Importante: The API controllers has a prefix on the route called api , so, when you create a controller that inherits from ApiController , it will be routed by api/ControllerName . 重要提示:API控制器在名为api的路由上有一个前缀,因此,当您创建从ApiController继承的控制器时,它将由api/ControllerName路由。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Web API添加到现有的ASP.NET MVC(5)Web应用程序项目? - How to add Web API to an existing ASP.NET MVC (5) Web Application project? 如何在同一项目中的ASP.NET MVC控制器中从ASP.NET Web API获取数据 - How get data from asp.net web api in asp.net mvc controller in the same project 如何将 web api 添加到现有的 asp.net mvc core 6 web 应用程序 - How do i add a web api to an existing asp.net mvc core 6 web application Castle Windsor ASP.NET MVC 4和Web API相同的应用程序。 只有MVC控制器没有依赖关系? - Castle Windsor ASP.NET MVC 4 and Web API same application. Only if MVC controllers have no dependencies? 在 ASP.NET MVC (5) 项目中使用 Web API 有什么好处? - What is the advantage of using Web API in a ASP.NET MVC (5) project? 在 web api 项目中使用 asp.net mvc - Use asp.net mvc within a web api project Asp.net MVC项目中的Angularjs调用Web API控制器 - Angularjs in Asp.net MVC project calling web api controller 如何在基于 cookie 身份验证的 asp.net mvc 项目中向 web api 添加令牌身份验证 - How to Add token authentication to web api in cookie authentication based asp.net mvc project 与OWIN集成的ASP.net MVC 5与Web API相同 - ASP.net MVC 5 Integration with OWIN same as Web API 将Asp.Net Mvc,Web Api应用程序发布到Windows Azure - Publishing an Asp.Net Mvc,Web Api Application to Windows Azure
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM