Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何通过web方法重定向到带有查询字符串的特殊页面_C#_Asp.net_Ajax - Fatal编程技术网

C# 如何通过web方法重定向到带有查询字符串的特殊页面

C# 如何通过web方法重定向到带有查询字符串的特殊页面,c#,asp.net,ajax,C#,Asp.net,Ajax,我为登录页面编写了一个web方法函数。当用户成功地对服务器进行身份验证时,我希望将其重定向到具有指定va的特殊页面 [WebMethod] public static string loginmtd(string username, string password , string chk) { datatable dt=filltable();//for bring data if (dt.Rows.Count==1) { if (chk == "ok"

我为登录页面编写了一个web方法函数。当用户成功地对服务器进行身份验证时,我希望将其重定向到具有指定va的特殊页面

[WebMethod]
public static string loginmtd(string username, string password , string chk)
{
    datatable dt=filltable();//for bring data
    if (dt.Rows.Count==1)
    {
        if (chk == "ok")
        {
            HttpCookie cook = new HttpCookie("userauth");
            cook["user"] = usern;
            cook["pass"] = passw;
            HttpContext.Current.Response.Expires = 60000;
            HttpContext.Current.Response.AppendCookie(cook);         
        }

    HttpContext.Current.Response.Redirect("master.aspx?uid=" + username);       
    return result;     
    }
    else 
    { 
        result = "no";
    }
}

对于web方法,不能在服务器端执行此操作。这是客户的责任

您可以遵循不同的算法:

  • 从客户端调用身份验证方法
    • 获取身份验证令牌并将其用于所有后续请求
  • 调用需要身份验证的web方法
    • 若用户并没有身份验证令牌,服务器将返回HTTP 401 Not Authorized
    • 若用户有正确的令牌,服务器将执行web请求并返回结果+HTTP200OK

还可以查看HTTP状态代码,它们负责客户端可能遵循或可能不遵循的重定向。

我不知道如何在webmethod中使用querystring。此代码无法重定向到新页面并返回主页(loginpg)。请花点时间格式化您的问题和代码。这将提高你获得好答案的机会!