Why an Introduction to ASP.NET on OpenShift?
In doing ASP.NET development utilizing OpenShift, I’ve found that a few tutorials out there for beginning on ASP.NET are
a) excessively mind boggling, and
b) don’t go over the rudiments of how it functions
In case will utilize ASP.NET on OpenShift, you should have the capacity to comprehend it!
In this instructional exercise arrangement, I’d jump at the chance to give you a fundamental comprehension of how ASP.NET functions and what you’re doing before you begin putting your undertakings on OpenShift. We’ll get to that in an article soon enough.
In parts 1 and 2 of this instructional exercise, I’ll be going over beginning rapidly by utilizing layouts in Visual Studio Community 2015. This implies it’ll be for Windows in this part. In any case, I’ll run more top to bottom with doing everything without layouts in Visual Studio Code in a taking after instructional exercise, which will be relevant to Linux or Mac and in addition Windows. In case you’re not utilizing Windows, you can in any case take after along in parts 1 and 2 to get a general thought of how to make a REST endpoint in .NET Core.
We should Begin!
Section 1 – Setting Up an ASP Service
Will begin you off by making a basic ASP service utilizing a Controller. I need to ensure you see how Controllers function before moving completely on to MVC.
MAKE YOUR PROJECT
In Visual Studio (I’m utilizing Community Edition 2015) click File and afterward New Project.
Under the Templates – > Visual C# – > Web organizer, select ASP.NET Core Web Application (.NET Core). It’s critical that you select the .NET Core and not the .NET Framework as this is the .NET cross-stage library.
Enter your venture name — this can be anything you’d like, in this instructional exercise I’ll be calling it MeowWorld.
As a matter of course, this location will be in your Visual Studio Projects organizer, yet don’t hesitate to change this in the event that you’d get a kick out of the chance to store the instructional exercise somewhere else.
We need to make another arrangement (an answer resembles an ace venture that holds the diverse activities you’ll be working with) and we need to name the arrangement something.
As a matter of course, the arrangement is named the same as your venture. This is splendidly fine, so abandon it as may be. Be that as it may, you’re more than welcome to rename it in the event that you’d get a kick out of the chance to.
Make sure Create a Directory is checked — this is not critical on the off chance that you comprehend what you’re doing, but rather it helps a great deal with keeping things composed.
You can likewise have Visual Studio make a git store naturally. I won’t do that as this is an instructional exercise, yet for a bigger scale extend, you may need to.
When you are content with every one of the settings, click OK to move onto the following stride.
SELECT YOUR TEMPLATE
Here you ought to have three choices. For this instructional exercise, you need to choose the Web API choice. I’ll get into the other two with future tutorials.
On the off chance that you assemble and run the venture at this moment, it will open a program window (or tab) and take you to …/programming interface/values/ — which will show a JSON cluster demonstrating this:
Close your program and ensure you stop your venture by squeezing the red square catch (which says “Quit Debugging” when you mouse-over) with the goal that you can alter it.
ALTERING YOUR CONTROLLER
In the Solution Explorer, go to Solution Name – > src – > Project Name – > Controllers – > ValuesController.cs and open it.
See how every one of the methods have a Http…“ trait related with them (HttpGet,HttpPost,HttpPut, andHttpDelete). This is the http method – HttpGet` is the run of the mill one utilized for getting to a web page. Contentions can be passed to every method as inquiry string factors (or course data — more on routes later).
Right-Click on the controllers envelope and make another class called CatController.
Add the Microsoft.AspNetCore.Mvc library to help keep your code perfect.
Add the accompanying Meow method to your class:
Now run the code. In your program, affix/cat/bill/to localhost:##### to see your work in real life.
You are evolving HttpGet(“/cat/bill”) to peruse HttpGet(“cat/bill”) and changing the name of the method from pubic string “Yowl()” to open string Bill().
Take note of that neither the name of the controller or the method influence the way. It’s regular practice to make everything match however, so refresh the code:
Now how about we include another cat!
Now you can run the code and open your program to: …/cat/steve/
We can continue including cats, yet making a method for every one can get to be distinctly irritating, so how about we change that. We can utilize a contention for the cat name that will be passed as a question string. So our code can now resemble this:
Now run the code and direct your browser to:
.../cat?cat=bill and then
Now we have the cats in a similar method, however the URL is somewhat jumbled. This is the place going factors through routes comes in. All we need is a little change to the code:
Furthermore, now we can backpedal to utilizing: …/cat/bill and …/cat/steve.
That is it for the initial segment of this presentation. In making these two ways for the cats and what they say, you’ve begun in making an ASP.NET web service with two API calls! My next post will discuss getting and setting data, and how sessions work, as we grow the cat swarm.