[WebMethod]
public string getUserName()
{
String userName ="";
HttpWebRequest userRequest = (HttpWebRequest)WebRequest.Create("http://localhost:82/getusername.aspx");
userRequest.Timeout = 20000;
HttpWebResponse userRespose = (HttpWebResponse)userRequest.GetResponse();
if(userRespose.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = userRespose.GetResponseStream();
StreamReader readStream = new StreamReader( receiveStream,System.Text.Encoding.Default);
userName = readStream.ReadToEnd(); userRespose.Close(); readStream.Close(); }
return userName;
}直接在浏览器中http://localhost:82/getusername.aspx访问有输出值,但是在上面的程序中就得不到username
是什么原因

解决方案 »

  1.   

    http://localhost:82/getusername.aspx
    代码可别告诉我你获取的username在Session里……
      

  2.   

    不太明白你的意思
    如果你想通过Ajax来获取数据的话,请看http://community.csdn.net/Expert/topic/5309/5309786.xml?temp=.2503473
    上面简单的介诏了一下AJAX应用,还有不太明白的再问吧。
      

  3.   

    username 在cookie 中。
    直接运行 http://localhost:82/getusername.aspx可以得到cookie。getusername code
    private void Page_Load(object sender, System.EventArgs e)
    {
    if(!IsPostBack)
    {
    string username;
    HttpCookie newCookie;
    newCookie = Context.Request.Cookies["userName"];
    if(newCookie==null)
    {
    username = "";
    }
    else
    {
    username = newCookie.Value.ToString();
    }
    Context.Response.Write(username); }
    }我想做个单点登陆,没有什么思路。
      

  4.   

    [WebMethod]又是Web服務﹐又去提取客戶端的cookies???