如何将服务器发送的Session_ID值存储在角度为2的本地存储中

时间:2017-08-23 15:35:17

标签: asp.net angular

成功验证后,我在响应标题中输入 _SessionId 值( Set-Cookie :ASP.NET_SessionId = 02jsm1y515st1at34tnym1uu; path = /; HttpOnly)。< / p>

我需要存储此值以将其发送回任何其他请求。

有什么想法。

注意:我正在使用CORS

的Global.asax

void Application_BeginRequest(object sender, EventArgs e){
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin" , "*");
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
    HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
    HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
    HttpContext.Current.Response.End();

}

Angular 2服务:获取方法

 login(value: any) {


    let headers = new Headers({ 'Content-Type': 'application/json' });
    let options = new RequestOptions({ headers: headers });

    let params = new URLSearchParams();
    params.set('module', 'login'); 
    params.set('user', (value.email).toString());
    params.set('pass', (value.password).toString());

    return this.http.get(this.loginUri, {  
        search: params  
    })
        .map(res => {
            console.log("===++" + res.text());
             console.log("=====" + res.text().replace(/([a-z][^:]*)(?=\s*:)/g, '"$1"'));


            return JSON.parse(res.text().replace(/([a-z][^:]*)(?=\s*:)/g, '"$1"'));

        })
    .catch(this.handleError)


}

screenshot of the response headers

0 个答案:

没有答案