Best way for C# desktop app to Web application - c#

I developed a desktop C# app with WPF UI.
What would be the best way to make this as a web application (I'm very new to web devlopment)?
The initial programm gets input via the UI and than does some calculations with the API of a 3D CAD-software. Afterwards, the results are visualized in the UI dashboard.
For that process I created classes and functions that get executed when the user clicks the "Calculate" button.
Can I - broadly speaking - put the whole code behind of the "Calculate" button in a Http Get method of a controller?
And what framework would be the best fit, ASP.NET MVC or ASP.NET Web API?
Most of the ASP.NET tutorials I watched dealt mostly with CRUD operations and databases, but I don't need one in the first place.
The UI I'd like to do with vue.js and JavaScript (if that even matters).

Its unnecessary to use CRUD operations if you dont need them. You can simply to create ASP.NET MVC or ASP.NET Web Api, they are same just different boiler plate. If you create asp.net mvc, you can delete the things wich don`t needed.
You say you want Vue.js for frontend so you need web api in backend!
I thin on creation asp.net api by default you don`t have any database. So you will use only controllers and other functions wich you have
Regards

Related

Can we set server-side session by making http call?

I am migrating old ASP.NET WEB Form project to Angular app with ASP.NET web API.
The requirement is to merge the newly designed angular module (say login section) with old asp.net application. The new application should be functional and work together with the old ASP.NET web form project.
Now the problem I am facing is, when I log in and try to navigate to other .aspx pages, they need some session values (which old login page used to set) to work without breaking the application.
I tried to achieve this by making HTTP call to a dummy .aspx page. I passed all the session values as query parameters and set in on the server side. It's working fine.
Is it a right approach for achieving this or is there any better way? Will there be any complication later as the application grows?

Security concerns calling an ASP.NET WebAPI from both the client and controller in an MVC app

I have an ASP.NET Core Web API application that is separate from my ASP.NET Core MVC application (UI). I didn't want to combine them for several reasons since in the future many different clients might need to access the API.
The MVC application makes calls to the API two different ways:
1. Using System.Net.HttpClient in the MVC controllers to populate the View Models.
2. When making jQuery AJAX calls I figured it would be best to directly call the API. (Note: I enabled CORS to allow calls from the MVC application). This would be the same thing as an Angular client making calls directly to the API.
My questions:
Is what I am doing pretty common making calls to the API directly from the client with jQuery and additionally System.Net.HttpClient in the Controllers when not using AJAX and just loading the view data. Should the AJAX calls go to the MVC controller first then let them MVC controller make a DELETE request using System.Net.HttpClient so I am never directly calling the API from the client?
What would the security concerns be? I am a bit nervous calling the API directly from jQuery. I feel like anyone can pretent they are localhost:6000 (my MVC port) and make a DELETE request to localhost:6001/api/users/1 (my API port).
You absolutely correct to be concerned about this. You should be securing your application from this making sure any requests to access these API methods are authorized.
I recommend reading 10 Points to Secure Your ASP.NET MVC Applications. for an overview on how to protect your application from this kind of attack and several other common security vulnerabilities.

How do I register an account on my MVC 5 Web App without using the form or webpage?

I have made a new project using the ASP.NET Web Application template in Visual Studio 2015. Then I selected MVC and Individual User Accounts to specify the template further. The solution I got is complete in that it offers me all the web pages you need for account management such as registering and logging in.
However, now I want to hook in a Xamarin.Forms mobile client to this account management scheme. I am making a native UI to register users, instead of redirecting them to a webpage or webview. I want to send user registration data, such as username and password, from this UI to the server so it will create an account. This means that I don't want to use the webpages offered by my MVC app, but rather send the registration data to the server and have it create an account, notfifying me of succes or failure.
I am anticipating that I would need to either use HTTP POSTs to login and registration endpoints in the AccountController or implement a public API. However, doing a post will return a webpage, and my client is not interested in a webpage.
I think one of the above should be possible to implement quite easily, but I am having a hard time searching for answers or methods, since I don't know how to phrase my problem properly, and with the abundance of guides on MVC, all my results are muddied.
Is my idea of this being possible flawed or have I missed a fundamental concept of MVC? What are the steps I should take in order to make this possible?
One misconception is that doing a POST will return a webpage. You can return any type of content from an MVC controller. But your account registration endpoints should be Web API controllers that return JSON. That JSON can be as simple as containing a boolean that indicates if the action was successful or not.
You do not need to use MVC at all. You can completely do away with the account controllers and views that the template created for you. Just copy the code that you need from the MVC controllers into your Web API methods.
You're right, this is quite easy to do.
I think, You can use ASP.NET Web API for doing this task. On server, you host your API for registering the users as well as logging into some client application.
Now, You need to consume this API in a client application. The client application could be a Console application, Windows application or a Web application. There are lots of tutorials about making an Web API on official ASP.NET site.

Can I implement MVC in Web Forms

I've got a simple thing to do - implement the login form. My employer wants me to use Web forms and my stubborn ass want's to implement the MVC pattern (I already have). The problem is I have no idea how to instantiate the Controller. I run debugging, get the view, but since there is no controller (or model), nothing happens when I click login since no one can respond to the event.
Where and how can I instantiate the Controller?
Yes, you certainly can.
I quote:
"As of 2014, the official answer to this problem is using Web API, as explained in this article I wrote for Simple Talk about a year ago.
Integrating a Web API layer into a Web Forms application couldn’t be easier. You just plug in the Web API runtime, configure routing so that you decide exactly which URLs you want to support and start writing your controller classes in the App_Code folder. Web API follows nearly the same programming model as ASP.NET MVC and is really easy to learn. In the end, it’s just like writing controller classes equipped with public methods callable from JavaScript clients.
ASP.NET Web Forms and ASP.NET MVC share the same runtime environment and requests are routed through exactly the same pipeline. It is even acceptable to say that ASP.NET MVC is just a global HTTP handler installed on the ASP.NET request pipeline. If the incoming request matches the URL requirements supported by the MVC handler then the request is routed to it; otherwise it is processed by the runtime as usual. “As usual” here means just as if it would go in a plain Web Forms application."
Here is the source of my above quoted information. I suggest you give this a read, as this is very useful and will give you a good understanding of the differences between both MVC and WebForms, and how can mix the architectures.

Best way/solution to display json data from a local winform .net app on angularJS web dashboard applicaiton

can u please help me out with the best solution how to do this?
I have a windows form application, which is continuously doing something. (making screenshots and generating data) This app is running locally.
So I dont want to use teamviewer from office just to see what my application is doing. I want to create an AngularJS Web Dashboard application (load it on a webhost) and display this winform data (in form of charts,..), so that I can access from everywere.
What is the best solution for this?
I have experience with AngularJS and parsing JSON-Files from a webserver.
I preffer creating/serialize a json file (each second) from my winform app and load it somewhere on webhost and then access this json file with http.get from my AngularJS application.
Is this a possible solution? Any suggestions?
Thanks!
I agree with making a Angular web app (although you don't need angular for this, you can use jquery to make a simple ajax call, seems like it would be quicker to add the jquery reference than to setup the angular scaffolding just for one or two ajax calls) to call a web request where the winforms app stores the data.
Ex. you can create a web request (or directory save) in winforms app to perform the 'snipping tool' action described here: C# snipping tool service and send the data to somewhere to store it. If the snipping tool doesn't work then probably use an export of the chart or data you are capturing. Then the web app can query that directory to retrieve (ajax/http get) whichever data you need.
I would advise clean up on that directory as it could become quite big if you are saving to it every few seconds or so.

Categories

Resources