Can a local html5 application have an asp.net session? (local webapp for iPhone)

Context:

I am actually developing a small web application (C # / MVC2). Users will use their iPhone (and possibly Android phones in the future) to access it.

This is quite simple at the moment (it just shows some information and reports from our ERP client), and I decided to try creating a local webapp that users could add to their iPhone so that they have an icon for this and, most importantly, most files are locally cached, so using json from the server only the relevant data is received.

Problem:

To authenticate users, a small form requests a username and password and sends them to the server via ajax, which, in turn, verifies the user and sets authcookie. If the application is run in Safari, everything works fine, but if it runs locally (that is, in Mobile Safari directly from the icon), the server correctly checks the user, but this check is lost when the next ajax call to restore data.

Does this mean that the session cookie is not supported by Mobile Safari in webapps? Am I doing it wrong?

And most importantly: what is the best way to authenticate users in a local webapp that accesses remote data?

+5
source share
4

, webapp. , HTTP-, localhost.

, http://localhost http://yourwebsite.com, localhost yourwebsite.com. , OAuth , .

webapp - . yourwebsite.com OAuth. , yourwebsite.com, localhost .

0

( , , ...)

Mobile Safari -, " " (.. -, iOS).

, , cookie, , Mobile Safari ? , : Mobile Safari, , .

, , , / , , VPN ? ( -).

0

, cookie, ajax- , "authcookie". localStorage .

http://dev.w3.org/html5/webstorage/

, -, (X- ) GET- URL-.

0

: http://www.asp.net/web-api/overview/security/individual-accounts-in-web-api

HTTP-

:

var loginData = {
    grant_type: 'password',
    username: ...,
    password: ...
};

$.ajax({
    type: 'POST',
    url: '/Token',
    data: loginData
}).done(function (data) {
    // Cache the access token in session storage.
    sessionStorage.setItem(tokenKey, data.access_token);
});

:

// If we already have a bearer token, set the Authorization header.
var token = sessionStorage.getItem(tokenKey);
var headers = {};
if (token) {
    headers.Authorization = 'Bearer ' + token;
}

$.ajax({
type: 'GET',
url: 'api/values/1',
headers: headers
}).done(function (data) {});

If you do not plan to use the web API, you must create your own token and put it in each data request

0
source

All Articles