Hola buenas haber si me podéis ayudar con este problema.
En el Web.config tengo esto.
Código:
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*"/>
<add name="Access-Control-Allow-Headers" value="Content-Type"/>
<add name="Access-Control-Allow-Methods" value="POST,GET,OPTIONS"/>
</customHeaders>
</httpProtocol>
<handlers>
<add name="MyHandler" verb="*" path="MyHandler.ashx" type="MyNamespace.MyHandler, MyNamespace, Version=1.0.0.0, Culture=neutral" />
</handlers>
</system.webServer>
Luego tengo un archivo ExisteUsuario.ashx que me devuelve si un usuario existe o no.
Código:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
namespace LolUp.ashx
{
/// <summary>
/// Descripción breve de ExisteUsuario
/// </summary>
public class ExisteUsuario : IHttpHandler
{
JavaScriptSerializer vSerializador = new JavaScriptSerializer();
public void ProcessRequest(HttpContext context)
{
mdLolUpEntities db = new mdLolUpEntities();
Dictionary<string, string> res = new Dictionary<string, string>();
String Respuesta;
T_Usuarios u = new T_Usuarios();
string email = context.Request.QueryString["Email"];
var bdUsuario = (from d in db.T_Usuarios
where d.email == email && d.user_delete == "0" //comprobamos que no este borrado.
select d);
if (bdUsuario.Count() == 0)
{
res.Add("Resultado", "0");//El usuario no existe en la base de datos.
}
else
{
res.Add("Resultado", "1");//El usuario existe en la base de datos.
}
Respuesta = vSerializador.Serialize(res);
context.Response.ContentType = "application/json";
context.Response.Write(Respuesta);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
y luego tengo la llamada ajax a dicho archivo.
Código:
var parametros = { "Email": $Usuario };
$.ajax({
type: "GET",
contentType: "application/json",
dataType: "json",
crossDomain: true,
data: parametros,
cache: false,
url: 'http://lolup.somee.com/ashx/usuario/ExisteUsuario.ashx',
success: function (data) {
alert(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert("ERROR: " + textStatus + "-" + errorThrown);
}
});
Vale dicho esto, os digo el error que me da.
XMLHttpRequest cannot load http://lolup.somee.com/ashx/usuario/ExisteUsuario.ashx?Email=Mikel&_=1418220562651. The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'null' is therefore not allowed access.
He buscado por google pero no consigo arreglarlo de ninguna manera haber si alguien me puede ayudar.