'访问控制允许来源'标头包含多个值' null,*',但只允许一个。起源' null'因此不允许访问

时间:2017-12-05 01:41:07

标签: asp.net

在webConfig中添加coors时,Owin信号器不起作用。

我做了一个api

        public ActionResult GetById(string Id)
        {
            Response<dynamic> result2 = new Response<dynamic>();

            var result = SolicitudServicioBl.GetById(Guid.Parse(Id));
            var x = result.Data;
            result2.Result = result.Result;
            result2.Message = result.Message;
            if (result.Result == Models.DTO.Response.Reply.success)
            {
                result2.Data = new
                {
                    Id = x.Id.ToString(),
                    x.Estatus,
                };
            }

            return Json(result2, JsonRequestBehavior.AllowGet);
        }

添加到webconfig后

 <customHeaders>  
        <add name="Access-Control-Allow-Origin" value="*" /> 
        <add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS,PUT,DELETE" />
         <add name="Access-Control-Allow-Headers" value="Origin, Content-Type, *" /> 
        <add name="Access-Control-Allow-Credentials" value="true" />
      </customHeaders>

一切运行良好,在添加了owin signalr之后,我添加了一个StartUp类

public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Any connection or hub wire up and configuration should go here
            //app.MapSignalR();
            app.Map("/signalr", map =>
            {

                map.UseCors(CorsOptions.AllowAll);
                var hubConfiguration = new HubConfiguration
                {

                };

                map.RunSignalR(hubConfiguration);

            });

        }
    }

问题在于,信号器不起作用:   &#39; Access-Control-Allow-Origin&#39;标头包含多个值&#39; null,*&#39;,但只允许一个。起源&#39; null&#39;因此不允许访问。

0 个答案:

没有答案