How can I create an ASP .NET MVC 5 solution? - c#

I never used ASP.NET framework before.
I saw some tutorial videos of ASP .NET MVC 5, but when I create a new project of ASP .NET MVC with .NET framework 4.8, the project doesn't have a StartUp.cs like the tutorial videos.
Can you tell me why this happen? And also how can I have the startup class in my project?
Edit:
I added images of what I'm asking. I hope that you can help me.
How the project is created
How the project has to be
Thank you very much.

I suppose that you need ASP.NET Core project not Framework.
You can check here project structure for asp.net core.

Related

Referencing .Net Core project from .NET MAUI

I have 2 projects in my solution - .Net Maui(GUI) and ASP.Net Core Web API(API)
After adding a project reference to my GUI I get the following errors:
And I can find very little information on that, although I'm probably looking in wrong places. Can you give a hand with that?
Edit:
To complete/expand my question, I'm looking for a way to structer my solution a little bit better, I don't want to have everything in .NET Maui project.
I was following this tutorial https://www.youtube.com/watch?v=LrZwd-f0M4I
The author does create .NET Core project for API and Db connection
(EF Core) and then he uses the Api in .NET Maui
What am I missing?

Can't find global application class nor Global. asax file

I want to add an API service to my existing .NET web application.
I was following this tutorial, but couldn't found any option to add web service.
Then I followed these two questions on Stackoverflow (Where is the Global.asax.cs file? and Global.asax file is missing on my Asp.Net Empty Web application project) but couldn't find the Add option for the global application class. How can I resolve this issue? Am I doing something wrong?
I tried to create a new solution, the problem is the same.
I'm using VisualStudio 2019 16.4.6
My project's targeted framework is .NET Core 3.1
If there is any tutorial or written document for adding web API to an existing project please give me, that would be very helpful. I tried to follow this blog and installed Microsoft.AspNet.WebApi.Core and got this warning -
Package 'Microsoft.AspNet.WebApi.Core 5.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
With ASP.NET Core, the entry point to an application is Startup, and you no longer have a dependency on Global.asax.
You can find more about it on this link
To consume an API you can use RestSharp in your Asp.net Core Application.
You can check this link to learn more about consuming an API using RestSharp in your Asp.net Core Application.
My project's targeted framework is .NET Core 3.1
Global.asax.cs will not be generated if you use ASP.NET Core. You have to use older version of ASP.NET, for example ASP.NET 4 (4.7.2) if you want to follow that old tutorial.
Or you can try a tutorial for WebApi using Asp.Net Core like this one: https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio

.NET Core 2.0 and Aurelia

Here's my story: I created a solution in VS2017 which contains 3 projects: .NET Core 2.0 dll to store my models, WebAPI (which uses EF Core 2.0 code first) and blank Web Application. In the blank project I would like to create a frontend Aurelia app. So, I did 'au new --here' on that project, selected TypeScript as my transpiler. Now, I have a solution with 3 projects which doesn't build because of:
Error TS5055 Build:Cannot write file 'XX/karma.conf.js' because it would overwrite input file.
I updated TypeScript to 2.3 by adding a proper entry to .csproj but still cannot compile my solution in VS2017.
My question is: how to add an Aurelia project to .NET Core 2.0 solution and get "au run --watch" works for it? I followed this post: http://mobilemancer.com/2016/10/19/aurelia-spa-typescript-dotnet-core/ but it seems not to consider all possible scenarios.
Please help me get started with .NET Core 2.0 Aurelia + WebAPI as I've been struggling with that for a couple of days.
You can look at the code from Aurelia-Typescript-Skeleton from GitHub https://github.com/aurelia/skeleton-navigation/tree/master/skeleton-typescript-aspnetcore
They have created asp.net core application and basic structure for aurelia and typescript.
You can install SPA Templates from ASP.NET core 2.0 with CLI command dotnet new --install Microsoft.AspNetCore.SpaTemplates::*
There you can find reach set of templates to start with ASP.NET core 2.0

Using Asp.net core security in MVC5?

We are using Adal as authentication library but we would like to use the policy functionality in Asp.Net Core security in our MVC5 application. The idea is to compile the Asp.Net Core library to .NET 4.6. This works! However, now I need to click the authentication things in my owin application.
Just adding the AuthorizeAttribute from the library doesn't work, it is not executed.
I have also read about the ported version from P. Schaeflein, but I would preffer to use the libraries provided by Microsoft.
Anyone an idea how to get this working?
Asp.net Core / .net core is a total rewrite of asp.net framework and the way it work is very different. For example Asp.net Core is most made around a Dependency Injection. So moving part of a framework that made for Asp.net Core to Asp.net MVC 4.6 made not work and would have to be rebuild to work with Asp.net MVC 4.6.

move to mvc from existing asp.net project

I have used .net framework 4.0 to design my web project I want to improve some features on my web site and I decided to use MVC in my project.
I research about mvc I found out System.Web.Routing in .net framework 3.5 is wrapped by System.Web in .net framework 4.0.
In the other side in my host environment I have IIS 7.0 with all necessarily handlers mapped to .aspx and some other extension like .cshtml and support them.
So I think I have all thing for mvc migration. my question is :
Is it possible to move mvc by configure web.config and make some structure for content, view and controller classes but don't change any asp.net pages and configuration like appcode and appdata which I had before in my asp.net application.
Note, I don't want to change or update my old application to mvc I want to add some mvc controllers class and view to my existing asp.net project to use mvc functionality.
Have a look at this walkthrough from Scott Hanselman:
http://www.hanselman.com/blog/IntegratingASPNETMVC3IntoExistingUpgradedASPNET4WebFormsApplications.aspx

Categories