解決
從跨域的.html頁面檢索的Web API會話數據
跨域資源共享是什麼,這是
ValuesController.cs(IN在Web API)
namespace TestWEB_API.Controllers
{
public class ValuesController : ApiController
{
// GET api/values
public string Get()
{
var session = HttpContext.Current.Session;
if (session != null)
{
if (session["Time"] == null)
session["Time"] = DateTime.Now;
return "Session Time: " + session["Time"];
}
return "Session is not working";
}// End Get()
...
}//End Class()
}//End Namespace
然後.html頁面(不在Web API !!!)在不同的.war
httpSessionTest.html
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="../Desktop/jquery-2.1.1.js"></script>
</head>
<script>
// !!------------- THIS IS WHAT I NEEDED! ---------------!!
$(function()
{
$.getJSON('http://localhost:Port/api/values', function(stringPayLoad)
{
alert(stringPayLoad);
$("#dataP").text(stringPayLoad);
});
});
</script>
<body>
<h3> Web API Session Test </h3>
<p id="dataP">!!! If you see this, it means that the session data didn't load. :(</p>
</body>
</html>
+1 HTML5本地存儲空間,這可能是存儲拉爾數據量的最好的地方爲每個客戶。如果在另一端有足夠的備用內存的整個計算機或智能設備時,爲什麼會阻塞服務器的內存? – mason 2014-09-11 01:38:39
100%同意你HTML5本地存儲我剛剛告訴他所有可能的選項 – ProgrammingNinja 2014-09-11 02:47:11
@ProgrammingNinja我如何從不在Web API中的HTML頁面訪問會話數據?(只是一個獨立的HTML頁面)我認爲這就是我需要 – 2014-09-11 21:30:17