Web API project template in VS - asp.net

Why can't we create WebAPI project directly just like "WCF Service Application" template in VS.I want to create separate solution not using MVC or ASP.Net WebForms template. In our project we intend to have service layer on different physical machine hosted by IIS to be consumed by different web applications.

The ASP.NET team is in the process of making their offering more cohesive, an effort they call "One ASP.NET." Under One ASP.NET, MVC, Web Forms, Web API, SignalR, and Entity Framework are all first class citizens. They want to make it easy to create web applications that utilize these technologies without having to give up the others; that is, you can make an MVC project but still use Web Forms; or a Web Forms project can easily add a Web API Project.
Anyway, back to your question: you can't create a Web API project directly (i.e. it's not in the main project template list) anymore because it has been rolled into the the single ASP.NET project type.
They explain,
Starting with Visual Studio 2013, the guessing game about which
project type to choose is over. There is now only one web project type
in Visual Studio.
As you can see from the list of templates, we can choose to start with
a standard Web Forms, MVC, or Web API project type. The other project
types from the old MVC template dialog are still here. The interesting
part is the checkboxes underneath the list of templates. Here, we can
choose to add Web Forms references and folders to an MVC project, or
MVC references and folders to a Web Forms project. This is the gateway
to using more of these features in concert with each other in your
project.
Read the full MSDN blog article about One ASP.NET and the new project types here
You can, however, still create a project (or solution) that contains just the Web API references. Just use the ASP.NET project dialog to choose the Web API project type, and make sure all the other check boxes are unchecked. You'll be able to make your project just for Web API, and then go host it on a dedicated box for your services layer. It's all still there, the UI just looks a little different.

Related

New ASP.NET Core MVC Project: "Empty" or "Web Application (MVC)"?

I need to create a new web application. The team has decided to use ASP.NET Core MVC (we all have experience with ASP.NET Framework MVC).
When going through the process of creating the new application, as per usual, I can choose to create an "Empty" project, or use a template like the "Web Application (Model-View-Controller)" application template.
I have always preferred using the Empty templates because:
I manually choose each dependency in application
I don't have to carefully delete things that I don't want included
However, I am wondering if the intention of these templates is to use them as a base template for new production applications.
This is my question:
Is the intention that new real applications that fall neatly into the "Web Application (Model-View-Controller)" category use that specific template (even though it includes extra sample files that will clearly need to be deleted)?
OR is the intention that new real applications start with a blank application and only include the dependencies you actually need, while the templates are more for learning/experimenting?
Answer: It would be better to use the MVC one since the project structure in the new ASP.NET Core is easy and clear and there are no longer complex configuration files or settings implicitly handled by Visual Studio. Everything (except the project files) in the MVC template is configured with C# code in a form of Fluent API. The initial contents in the MVC template are just a demo for how it work with the fresh new ASP.NET Core which can be very useful for ASP.NET developers to learn the whole structure and pipeline things of a simple ASP.NET Core application. And you can remove everything easily and completely whenever you want.
By the way, "ASP.NET Framework MVC" does not exist for the old one that works with .NET Framework is named "ASP.NET MVC", and the new one called "ASP.NET Core" does not target .NET Core but .NET Standard, which means it works with both .NET Framework and .NET Core.
Additionally, It would be a better practice to use VSCode and .NET Core SDK with its command line tools than to use Visual Studio. It is light, portable, fully featured, and works more natively with portable things like batch scripts for automatic building, publishing and deploying on Linux.

How to use ASP.NET MVC Master Pages Solution in Individual ASP.NET MVC Projects

We have an ASP.NET MVC project to serve as a master portal. The portal has links to controllers/views in other ASP.NET MVC projects. When the link is clicked, we want to a view from a different MVC project is loaded into the body of the master portal.
We know ASP.NET MVC provides Area within the MVC project to organize related functionality into a group functions. But instead everything in a project, we prefer to have related functionality into a separate project but they share the same master portal.
Is it doable within ASP.NET MVC and how?
Depend on what is your exact requirement,
If you want to share only data between projects expose controller
actions and share the data by means of JSON.
Sharing UI between project may not come handy in the long run.
Before anything, have a look at this article
Always there is way to do everything in programming, but consider performance and best practices to keep your application long living.

can I add the Web API folders to an existing project?

Microsoft has a great tutorial here for learning how to build Web API web apps in Visual Studio 2013:
http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api
in it, he shows you how to include the Web API folders and references:
...is there a way to add these to a previous ASP.NET Webforms project that didnt have that checkbox selected? I'm working on an existing app and want to add Web API functionality to it.
thanks
yes -- there is a tutorial for adding Web API to an existing ASP.NET Webforms project here:
http://www.asp.net/web-api/overview/creating-web-apis/using-web-api-with-aspnet-web-forms
...it doesn't create the Models, Controllers, or App_Start folders, but i added them manually and placed my files from another stand-alone project there. once adjusting the namespaces it all operates properly.

I'm having trouble understanding exactly what ASP is and how to upload an ASP website

As of the start of this week I've been required to start learning how to develop websites in ASP. I have a moderate level of experience with C# through XNA, so that part of it isn't much trouble for me.
I've been following a Music Store Tutorial which takes me though setting up an "ASP.NET MVC 3" application.
I'm about done with the tutorial and have a functioning site when I run a test locally, but I don't understand what files need to be uploaded. I've worked on front-end updates for ASP websites before but they were completely different to this in terms of what files made up the site and so on.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience. I'm starting to think that those projects weren't MVC projects but maybe just the "ASP.NET Web Application" style project.
Are ASP.NET and ASP.NET MVC different? From what I vaguely understand, MVC is just a framework that wraps ASP.NET? Also, is ASP something or is that just a synonym for ASP.NET? Finally back to my initial confusion, what files are to be uploaded onto the server when I want to launch an ASP.NET MVC project?
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
ASP is an acronym for Active Server Pages. Pre .NET, ASP was Microsoft's first iteration scripted web pages. All of those pages typically ended with the extension .ASP.
When .NET was released, ASP was overhauled significantly and renamed ASP.NET. The new version of ASP.NET attempted to model web development similar to windows application development, where you used controls and an event handling model. That was Microsoft's primary model for web page development for many years, and it still around and supported, but today it is referred to as ASP.NET Web Forms. ASP.NET Web Forms pages typically have the .ASPX extension you mentioned.
In the mid-2000s or so, Ruby on Rails took off, using an MVC based model for developing web applications. A few years later, Microsoft released an alternate version of ASP.NET, called ASP.NET MVC, which used similar concepts. Many people feel the MVC approach is a more natural method for developing web pages than the web forms model (note epic Q/A threads on this very site a few years ago). In any case, ASP.NET MVC shares parts with ASP.NET Web Forms, but looks and works pretty differently; for one thing, there are no .ASPX pages as MVC, for the most part, uses a different form of routing to determine what to display.
That's a very brief history that glosses over a whole lot of subjects. What you've posted a screenshot of, is an ASP.NET MVC project.
As far as publishing is concerned, the typical route for publishing an ASP.NET website is to open the project in Visual Studio, select Build|Publish, and tell VS where to put it. Depending on what method you use, you may have to do additional configuration in IIS on the box where you published the site.
First off, when you say ASP, you're referring to old (obsolete) tech. ASP.NET is specifically what you're referring to in your question.
ASP.NET is a Microsoft technology which works cooperatively with the IIS server to provide a "Windows Application" type experience with web sites. Your web site logic is compiled in to a .NET DLL "Class Library." When a web request hits IIS with a URL matching your application directory, IIS starts up your application internally and maintains it.
I don't understand what files need to be uploaded
Visual Studio actually has a built in publisher available for your use. See the Build -> Publish menu in VS / Web Developer.
I don't see a single .aspx page in my project which is what I assumed an ASP site was made of from experience.
ASP.NET Web Forms uses the aspx extension for Pages, their frontend rendering component. On the other hand, ASP.NET MVC uses the concept of Views, which are not relient on a specific component. See the next paragraph.
Are ASP.NET and ASP.NET MVC different?
Yes. No. Maybe. ASP.NET contains all the "magic" which allows IIS - the web server - run the web application and serve up web pages. Volumes could (and have) been written on this. ASP.NET also supports much configuration through the means of Http Modules and Providers. These components are declared and configured through the web apps web.config file and are typically automagically created and persisted by IIS and ASP.NET. They collectively make up the glue that makes ASP.NET just work out of the box.
MVC was built on top of the existing foundation classes of ASP.NET. Some features have been loaned, a few have been replaced and more than a handful have been created in order to support the model-view-controller pattern.
For example, MVC gives us support for View Engines - a runtime library which allows us to write our Views (web pages) in a particular format. The ASPX View Engine existed during MVC's launch. Later came Razor, employing the .cshtml extension. Users of the MVC Framework have implemented a wide variety of their own view engines as well. This is possible due to the modular nature of ASP.NET and MVC.
Do I just upload this entire directory and the server will handle it in the same way that the inbuilt testing ASP server does? Or is the site compiled down into a couple of files somehow and I just upload one of these directories (I think I read that somewhere).
I would recommend using the Build -> Publish menu in Visual Studio. You may use web deploy if your host supports it, but FTP and File System methods are available as well.
The bin folder contains the class libraries required to run your web application on the server. The web.config file provides the configuration to do so. However your Views are not compiled in to the assembly. They are published as-is and are rendered lazily by the view engine.
You are probably familiar with ASP.NET WebForms, this is an MVC project. You can find more here:
ASP.NET MVC
In order to upload the site, you need to publish the website from inside Visual Studio to a local file location and then upload everything to the website.
If the target server doesn't have MVC installed, you can right click on the website project in Visual Studio and select "Add Deployable Dependencies".
This will ensure that the server has all the required files to run an MVC project.

Adding a Single Web Service to an Existing ASP.NET Application

I've written an ASP.NET website along with a companion WinForms desktop application, which is used to maintain the site.
The desktop application needs to create a user. However, this is awkward because I would need to ensure all the membership settings are exactly the same as they are in my website's web.config file.
It would be easier if my desktop application could "call into" the website somehow and tell it to create a user. It seems like a web service would be a good option for this. However, Visual Studio doesn't have an option to add an ASMX file. And if I create a separate, web service application, then that application would have the same problem my desktop application has.
Is there a way to add a single web service to an existing ASP.NET application? Any links? Thanks.
Visual Studio doesn't have an option to add an ASMX file
In the Web application project, or the WinForms project? I assume you mean that you cannot add a Web Reference from within your WinForms project; adding an .asmx file to the WinForms project is not necessary. The Web application project should have the .asmx file, which is called by the WinForms project using a web reference.
In the WinForms project you can consume a web service by right-clicking References in the Solution Explorer, then choosing Add Service Reference... (in Visual Studio 2008; other versions may say Add Web Reference...). Then just enter the web address (which may be local in your case, e.g. localhost/foo.asmx) of the web service (.asmx).
See the section "To call an XML Web service synchronously" in this MSDN article: Calling XML Web Services from Windows Forms.
As an alternative, this MS KB article shows how to use the WSDL tool to generate a class that can consume a *.asmx URL. (The article uses VB, but you can switch the parameter to CS to generate C#.)
Update
To add an .asmx file to your Web project, right-click the project in Visual Studio, select Add -> New Item... -> Web Service. If there is not a "Web Service" item any where in the template browser dialog that comes up, then you are missing the template or you're looking in the wrong place.

Resources