Tracking which application sends data to a web api - c#

I have a PC based application and mobile app that both send data to my MVC Web API. I was wondering if anyone tracks which application inserted data to the server database?
For instance, when I send data from the mobile app, I mark a IsMobile flag in my table when I insert data.
If the answer is yes, can you briefly explain how you accomplish this and what issues it may have saved you from?

You could make this as parameter in your web api call and the mobile client sends it with the value "mobile" and the PC sends it as "PC"
In the MVC controller this comes as a variable and then you can store it.

I decided to use the User-Agent route. I am now creating a log the inserts the HttpContext.Current.Request.UserAgent from every request made to my web API. Here is a link that helped me out.

Related

Login Authentication using self hosted API (WPF)

I'm developing a system with my classmate, he created a self-hosted API using WPF, while I'm on the mobile part. I already get the data using GetAsync and Post data using Post Async, What I want now is Login Authentication to our system.
Here is the Web API I'm talking about.
What I want is to use this as my API for authentication, But whenever I search for this topic, all of the results are Azure, WCF, ASP.Net.
I know that my friend uses ASP nugget to create API while searching so far on this topic. Theirs always using those 3 and the codes for validation is in the ASP, WCF or Azure.
I also don't get the concept of a token and I guess I don't need it on the self-hosted API.
This is the best example of what I'm talking about:
http://www.c-sharpcorner.com/article/xamarin-android-create-login-with-web-api-using-azure-sql-server-part-one/
http://www.c-sharpcorner.com/article/xamarin-android-create-login-with-web-api-using-azure-sql-server-part-two/
These two set of tutorials are very helpful, but I'm not aiming for this thing. I just want a simple authentication using the API on the picture.
It's just a simple school work, I'm the beginner in mobile development and c#.
Thanks in advance for viewing my POST :)
While your question is waaaaaay to broad for a single answer on Stack Overflow, here are some pointers for you. Don't overthink things and keep it simple.
I think the easiest way to tackle your problem is to issue a token for your mobile app. This can be any type of token if you don't really care about security.
So in your app, you present the user with a username/password dialog. Pressing a login button:
you hit your API sending that username and password
API checks whether username and password is in database or a valid combination
generates a token if OK and sends as response and saves that token in database
then when hitting other urls in your API from mobile app, you need to provide the token as header or query string parameter
This is probably the simplest form of authentication you can do.

Simple API call to management.azure.com

I am building a very simple maintenance app for a website hosted on Azure. I want to display a few details such as website online status (on/off), server location, latest deployment(s) and so forth. So rather then browsing the azure portal I want to see a few things on a single page in the maintenance app.
https://resources.azure.com shows off the azure management API I want to use.
The question is how can I get back a JSON object with information displayed above?
A call would be made at the following url: https://management.azure.com/subscriptions/subscription_id/resourceGroups/Default-Web-NorthEurope/providers/Microsoft.Web/sites/my-website?api-version=2014-06-01
Apart from the API endpoints, the application above doesn't tell me much.
For example how does the authentication object needed looks like (the one used during a GET/POST)? I am building this in C#.
This helped me so far :
http://blogs.msdn.com/b/tomholl/archive/2014/11/25/unattended-authentication-to-azure-management-apis-with-azure-active-directory.aspx.
though I have still having issue on udating it but I'm getting the json data.

Rest Web Services and session handling for multiple clients

I have been working on a RESTful webservice for an android native application to consume. I choose ASP .NET WEB API. WEB API makes it very easy to create those HTTP methods in controllers, and converting our response objects into json/xml... Its simply awesome!
Now comes user authentication and those session handling parts. First I thought it will be easier to implement sessions in my RESTful service. But really frustrated with the configurations for enabling sessions in WEB API, and making the android native to handle those session ids.
First, Android sends login request to WEB API
WEB API checks authentications, and responses with a sessionid in response header
Now Android native reads the response header->fetches ASPNET_sessionId ->keeps in its memory
Further requests from android will have to set this ASPNET_sessionId in request header
Do you think this is a proper way?
And now I have another client. A hybrid app in Mobile jquery. Now facing following problems:
Access-origin policy: So I set Access-Control-Allow-Origin to * in response header. And it solved.
Now I need to set session id in jquery ajax post request. And found its not possible to set headers for jquery ajax when calling a cross domain service.
How can I manage session for my hybrid app?
Also What are the things taken care of while creating a web service that has to be consumed from different client applications?
After a lot of research I have come with following points:
REST is stateless. So why do we need to play with session? there by giving it a stateful life?
No need for enabling session state. When a user logins into
application we creates a unique id for user in database. Further
requests from the user will send this unique id as a part of message
body. Server checks this unique id every time for identifying user.
Cross-domain issue in Hybrid app
When converting app to hybrid with cordova we found that cross domain
issue is not occuring. It is believed that cordova converts jquery
ajax requests to native requests calls from android. jsonp also found to be a good solution.

Which application is better to develop for the following requirement

I need to store data received from a remote device, i.e Application needs to run 24 hours so that it can capture data and store it in database.
I am confusing whether to create a console application, web application or any other i need to develop which will run continuously.
If you already have the application developed, then send the data to a web service. if you don't, consider creating a web page, either using ASP.Net or something like JQuery Mobile and push data to HTTP Handlers or Web Service.
If you go down the web service route, create a web method that accepts a request object and returns a response object. It should be a pretty simple design.

File Upload to HTTP server from iPhone application. Server side C# API method

Could someone please tell me/link me to how I could create a method similar to those posted below:
http://www.vimeo.com/api/docs/upload
http://www.flickr.com/services/api/upload.api.html
(I am providing the links as I'm not sure how to articulate this question without them!)
I'm using C# ASP.NET. IIS 6.
I have an existing web server with other public API methods. I do not want the iPhone user to have to open a web browser, and post to an aspx page. I want the iPhone developer to be able to call my method, and have one of the parameters be a handle to the file which gets POSTed.
Thanks in advance for any help.
You'll need to create a WCF Service Application. You can use this as a webservice that can be exposed to your clients. You can create a RESTful service using WCF where clients can POST video's to.
When searching for 'REST, API, WCF' you'll probably find all the resources you are looking for.

Categories