C# 从服务器重定向新页面
我有一个WebMethod,可以重定向到该服务器上的另一个页面C# 从服务器重定向新页面,c#,asp.net,webmethod,C#,Asp.net,Webmethod,我有一个WebMethod,可以重定向到该服务器上的另一个页面 [WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Xml)] public static Boolean realizaConsulta(Dictionary<string, string> datos) { System.Web.HttpContext.Current.Response.Redirect("PRepConsulta.aspx",
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public static Boolean realizaConsulta(Dictionary<string, string> datos)
{
System.Web.HttpContext.Current.Response.Redirect("PRepConsulta.aspx", false);
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Xml)]
公共静态布尔值(字典数据)
{
System.Web.HttpContext.Current.Response.Redirect(“PRepConsulta.aspx”,false);
}
但我得到了这个错误:
Microsoft JScript运行时错误:Sys.Net.WebServiceFailedException:
服务器方法“RealizationConsulta”失败,出现以下错误:
System.InvalidOperationException--身份验证失败
是什么导致了这个错误
看看我尝试过的其他选项:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public static Boolean realizaConsulta(Dictionary<string, string> datos)
{
System.Web.HttpContext.Current.Server.Execute("PRepConsulta.aspx", false);
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Xml)]
公共静态布尔值(字典数据)
{
System.Web.HttpContext.Current.Server.Execute(“PRepConsulta.aspx”,false);
}
它可以工作,因为它会转到PRepConsulta.aspx并执行UNDERCODE,但页面从未显示
我也尝试过:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public static Boolean realizaConsulta(Dictionary<string, string> datos)
{
HttpContext.Current.Server.Transfer("PRepConsulta.aspx", false);
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Xml)]
公共静态布尔值(字典数据)
{
HttpContext.Current.Server.Transfer(“PRepConsulta.aspx”,false);
}
但我有一个错误:
Microsoft JScript运行时错误:Sys.Net.WebServiceFailedException:服务器方法“RealizationConsulta”失败,出现以下错误:System.Threading.ThreadAbortException--SubSecso anulado
我不知道还能尝试什么
感谢您的帮助我不确定“身份验证失败”部分是否正确,但有一个响应。WebMethod内部的重定向可能会破坏调用该方法的SOAP客户端。它需要的是布尔值,而不是重定向。好的,我将组织应用程序的流: 从我的客户端,在javascript中,我调用了一个web服务 PageMethods.Consulta(Datos); 在我的codebehind中,我必须执行pageMethod并调用另一个页面
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Xml)]
public static Boolean realizaConsulta(Dictionary<string, string> datos)
{
clsGeneral consulta;
DataTable dtTemp = new DataTable();
using (consulta = new clsGeneral("SQLConn"))
{
consulta.consultaPrograma(ref dtTemp, datos["Codigo"], Int16.Parse(datos["Cod_Actividad"]), Int16.Parse(datos["Cod_SubActividad"]), datos["FechaIni"], datos["FechaFin"]);
HttpContext.Current.Session["Consulta"] = dtTemp;
//THIS ARE THE 3 DIFFERENT WAYS I HAVE TRIED TO CALL THE PRepConsulta.aspx,
//I DONT KNOW IF THERE IS A BETTHER WAY TO DO IT
//System.Web.HttpContext.Current.Response.Redirect("PRepConsulta.aspx", false);
//HttpContext.Current.Server.Transfer("PRepConsulta.aspx", false);
//System.Web.HttpContext.Current.Server.Execute("PRepConsulta.aspx",writer, false);
}
return true;
}
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Xml)]
公共静态布尔值(字典数据)
{
总领事馆;
DataTable dtTemp=新DataTable();
使用(consulta=new-clsGeneral(“SQLConn”))
{
咨询顾问程序(参考dtTemp、datos[“Codigo”]、Int16.Parse(datos[“Cod_Actividad”])、Int16.Parse(datos[“Cod_SubActividad”]、datos[“FechaIni”]、datos[“FechaFin”]);
HttpContext.Current.Session[“Consulta”]=dtTemp;
//这是我尝试调用PRepConsulta.aspx的3种不同方式,
//我不知道是否有更好的方法
//System.Web.HttpContext.Current.Response.Redirect(“PRepConsulta.aspx”,false);
//HttpContext.Current.Server.Transfer(“PRepConsulta.aspx”,false);
//System.Web.HttpContext.Current.Server.Execute(“PRepConsulta.aspx”,writer,false);
}
返回true;
}
感谢您没有更好的地方放置此回复。。。听起来你并没有真正告诉浏览器重定向。无论您如何连接JavaScript来调用web服务,它都在调用它并接收布尔值以外的内容(这正是它所期望的)。对web服务的SOAP调用的上下文与您正在查看的web页面的上下文不同。浏览器在任何时候都不会被告知重定向到另一个页面,相反,它只是调用一个SOAP方法并接收到一个意外的响应。重定向逻辑基本上位于错误的位置。调用WebMethod的目标是什么?是否要显示其他内容,或根据正在传递的数据将用户发送到适当的页面?您最好只是将查询字符串中的数据传递到一个新页面,然后从那里重定向。在这种设计中,重定向的位置是错误的。如果用户总是被重定向到另一个页面,那么您可能想要:1)将用户从JavaScript重定向到一个新页面,并在该页面加载时调用此逻辑;2) 在调用此WebMethod返回后,将重定向放在JavaScript中。将重定向放在WebMethod中不会告诉浏览器重定向,它只会破坏返回值。我在Begging中就是这样做的,我调用了WebMethod,之后,我调用了新的page by window.open函数,但是,当我将项目上传到服务器时,我意识到窗口在webMethod结束之前打开。webMethod运行一个查询,我将结果保存到会话变量中,并在下一个打开的窗口中使用它。这就是我试图从服务器打开窗口的原因,因为我需要确保查询已经运行并且结果在我的会话变量中。当然,有一种方法可以等待返回、检查值并相应地响应(使用重定向或错误消息)。另外,首先通过JavaScript调用此WebMethod是否有特定的原因?似乎有一些更大的图景影响了这个设计,但这里不清楚。好吧,我解决了它,正如你所说的,我根据响应执行另一个函数:PageMethods.realizationConsulta(Datos,onLoadDatos);函数onLoadDatos(response){if(response){window.open(');}否则{alert(“error”)}谢谢您的回答!!