我的代码所做的是在数据库中搜索写入参数的URL,如下所示。因此,当我返回URL并打开而没有用户单击超链接时,错误说:线程正在中止。
我将url保存在数据类型字符串中,因此使用Response Redirect我想打开页面。
public void Consultar()
{
try
{
string s = System.Configuration.ConfigurationManager.ConnectionStrings["dba"].ConnectionString;
SqlConnection conexion = new SqlConnection(s);
conexion.Open();
// 1. create a command object identifying
// the stored procedure
SqlCommand cmd = new SqlCommand("spBuscarUrl", conexion);
// 2. set the command object so it knows
// to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
// 3. add parameter to command, which
// will be passed to the stored procedure
cmd.Parameters.Add(new SqlParameter("@CodigoContrato", TextBox1.Text));
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.Read())
{
this.HyperLink1.Text = rdr["URL"].ToString();
}
string hyperLink = this.HyperLink1.Text;
if(hyperLink != "")
{
Response.Redirect(hyperLink);
}
}
catch (Exception ex)
{
// Response.Write("<script LANGUAGE='JavaScript' >alert('Hubo error en la consulta')</script>");
throw new Exception(ex.Message);
}
}