Can we write the .net core WebAPI in the asp.net core razor web page itself? - asp.net-core

I have the following projects in my solution all .net core 5.0.
myproject.domain
myproject.infrastructre
myproject.webAPI
myproject.UI.Razorweb page.
Instead of using SPA which calls the webAPI, I am using razor web page which will call the webAPI(.net 5.0). My question is can we merge the webAPI and the razorwebpage into one? Can we write webAPI in the razor web page itself?
Is that allowed?

I agree with the suggestion given by Jeremy.
You should have a web API and Razor project separate.
Besides, if you would like to make some tests then you could refer to the articles below.
Use Razor Pages, MVC, And Web API In A Single ASP.NET Core Application
Hosting ASP.NET Core Razor Pages and Web APIs in a Single Project
Razor pages and webapi in the same project

Related

What does it mean by support for Razor Pages is built on ASP.NET Core MVC?

I know mvc model view controller.
I know razor pages.
Both of the above are separate project templates and may be included within the same solution.
I know razor syntax can be used on MVC views as well as razor pages.
I am reading that:
Support for Razor Pages is built on ASP.NET Core MVC.
ASP.NET Core MVC also supports Razor Pages, a simpler way to organize MVC-style pages.
ASP.NET Core supports both MVC (Views or Page based)
What does it mean by support for Razor Pages is built on ASP.NET Core MVC?
Does this mean that Razor Pages are also MVC-style pages?

In ASP.Net Core 5.0, how do I route an old .aspx webform to a controller action hosted in IIS

I have re-written an old Webforms site into ASP.Net Core 5.0 MVC. There are thousands of links to the old .aspx pages indexed by search engines.
What is the best way to Route/Redirect the old .aspx pages to the new controller actions. For example:
The existing link is "https://mywebsite.com/quote.aspx" and I wish to route to "https://mywebsite.com/quote/index".
I found some threads using ASP.Net but can't find a working answer for ASP.Net Core.

Is there any way to use ASP.NET CORE MVC and WEB API together?

I am new to ASP.NET CORE and interested in how MVC and WEB API could be combined together? For example is there any way to use WEB API for back-end and MVC for front-end? The application should be simple CRUD app.
Easiest way is to create an MVC application.
Just create an api-controller inside and you have both!
A web api is just MVC, without the V, that is a model and a controller, no view.

Web Application vs Web Api project types in Asp.net Core

I know that Asp.Net MVC and Asp.Net Web API were merged into one code in Asp.net Core and they inherit from Controller base class and can all return implementations of IActionResult. it be a View for MVC or Json for web api.
But when i want to create a Asp.net Core project, it offers two templates (Web Application and Web Api ), according to what i said in above, there is no differences between these controllers, why there is two templates? is there any differences that i don't know about it?
The web application template will create folders and import stuff needed for a web application such as jquery, css etc. Web api template will create folders and import stuff for a web api. Also the controllers created by default will have different implementations, for example, web application will be returning views and the views will be created in the appropriate folder.
So although they derive from the same controllers, each type of project requires different dependencies.
If I were you I would go ahead and create one for each type and see the difference.
If you want to have both web api and web application in the same project, use areas. This way your web and api will have separate controllers, folders and models. Also if you want to separate them in the future, it will be easy to do so.
The difference between 2 templates is-
The WebAPI template starts with a Controller class that will allow you to respond to RESTful requests at the /api/Values endpoint.
The Web Application template will give you an MVC framework enabled project with some Razor views, the bootstrap CSS framework and jQuery library installed.
If you want to create project with both MVC and API controllers then I would suggest to go with ASP.NET Core Web Application template and add require dependencies.

How to use Devexpress report in Asp.Net MVC 4 Web Application(Not DXperience v12.2 ASP.NET MVC Web Application )

I want to use Devexpress 12.2 xtrareport in Asp.Net MVC 4 Web Application.Now i think you will suggest me Create an ASP.NET MVC Application and Add a Report to It but in this they are using DXperience v12.2 ASP.NET MVC Web Application and i am using Asp.Net MVC 4 Web Application.
Is this possible ?
This is the solution which i find out :
1.)Please review the How to: Manually Register DevExpress Extensions to Start Using Them in an MVC Web Application documentation article to learn how to register DevExpress ASP.NET MVC extensions manually.
2.)This way, you will be able to create a reporting application using the approach from the
Create a Basic Report in ASP.NET MVC documentation article.