在SignalR Hub中创建cookie表示响应在此上下文中不可用

时间:2018-10-19 08:09:57

标签: asp.net asp.net-mvc signalr signalr-hub signalr.client

下面是我的SignalR集线器代码,在其中创建cookie时会给出异常。

using Microsoft.AspNet.SignalR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using Test.Models;

namespace Test.Classes
{
    public class HomeHub : Hub
    {
        public void Login(LoginModel model)
        {
            HomeManager manager = new HomeManager();
            ActionOutput<UserDetails> Result = manager.LoginUser(model);
            if (Result.Status == ActionStatus.Successfull)
            {
                HttpCookie auth = Common.CreateCustomAuthorisationCookie(model.Username, false, new JavaScriptSerializer().Serialize(Result.Object));
                Context.Request.GetHttpContext().Response.Cookies.Add(auth);
            }
            Clients.Caller.loginCallback(new ActionOutput { Message = Result.Message, Status = Result.Status });
        }
    }
}

enter image description here

0 个答案:

没有答案