当前位置:编程学习 > C#/ASP.NET >>

请问如何在BS架构下为外部网站设置自动登录?

    公司内部有好多个系统,都是BS架构的,有各自的登陆界面,领导要求做一个BS架构登录整合的系统,每个用户在这个系统中设置一次其他系统的用户名和密码,以后在登录时只需登录整合后的系统,点击按钮或菜单就可以使其他系统自动登录。我不打算直接登录到系统中,只要将其他系统登录页面中的输入控件赋值就行了,然后用户点击各系统的登录按钮再进行登录。
    我现在用的是<iframe>标签,设置runat="server",在后台设置<iframe>的src="xx.html/aspx"等系统登录地址,这样可以在自己的母版下打开其余系统。我可以通过查看源文件或者别的方法获得其他系统输入用户名、密码控件的id、name,如"uid","password"。但是,如何才能使我在点击我的系统中菜单或按键时候能为其他系统的<input>控件自动填写上用户名和密码呢?
    我看在WinForm下可以做到,在Web下也可以做到吗? asp iframe 外部系统 自动登录 --------------------编程问答-------------------- 急!求助各位了! --------------------编程问答-------------------- 可以为每个系统设置一个桥页,接受从querystring传来的用户名、密码(本身最好编码下,并且用随机的token加密,保证其一次性有效,防止被盗用),然后登录自己的系统。
主系统通过相反的算法得到这个url,并且跳转过去。 --------------------编程问答--------------------
引用 2 楼 caozhy 的回复:
可以为每个系统设置一个桥页,接受从querystring传来的用户名、密码(本身最好编码下,并且用随机的token加密,保证其一次性有效,防止被盗用),然后登录自己的系统。
主系统通过相反的算法得到这个url,并且跳转过去。

如果其他的系统无法更改或者更改代价很大,只能从我的系统里面处理该怎么做? --------------------编程问答-------------------- 我在网上看到有用HttpWebRequest 做的,代码如下:
private void Post( string url , string indata )
    {
        string outdata = "";
        CookieContainer myCookieContainer = new CookieContainer();
        HttpWebRequest myHttpWebRequest = ( HttpWebRequest ) WebRequest.Create(url);
        myHttpWebRequest.ContentType = "application/x-www-form-urlencoded";
        myHttpWebRequest.ContentLength = indata.Length;
        myHttpWebRequest.Method = "POST";
        myHttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; Q312461; .NET CLR 1.0.3705)";
        myHttpWebRequest.CookieContainer = myCookieContainer;
        //设置HttpWebRequest的CookieContainer为刚才建立的那个myCookieContainer 
        Stream myRequestStream = myHttpWebRequest.GetRequestStream();
        StreamWriter myStreamWriter = new StreamWriter(myRequestStream , Encoding.GetEncoding("gb2312"));
        myStreamWriter.Write(indata , 0 , indata.Length);
        //把数据写入HttpWebRequest的Request流 
        myStreamWriter.Close();
        myRequestStream.Close();
        //关闭打开对象 

        HttpWebResponse myHttpWebResponse = ( HttpWebResponse ) myHttpWebRequest.GetResponse();
        //新建一个HttpWebResponse 
        myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
        //获取一个包含url的Cookie集合的CookieCollection 
        Stream myResponseStream = myHttpWebResponse.GetResponseStream();
        StreamReader myStreamReader = new StreamReader(myResponseStream , Encoding.GetEncoding("gb2312"));
        outdata = myStreamReader.ReadToEnd();
        //把数据从HttpWebResponse的Response流中读出 
        myStreamReader.Close();
        myResponseStream.Close();
        Console.WriteLine(outdata);
        //显示"登录" 

        //拿到了Cookie,再进行请求就能直接读取到登录后的内容了 
        myHttpWebRequest = ( HttpWebRequest ) WebRequest.Create(url);
        myHttpWebRequest.CookieContainer = myCookieContainer;//* 
        //刚才那个CookieContainer已经存有了Cookie,把它附加到HttpWebRequest中则能直接通过验证 
        myHttpWebResponse = ( HttpWebResponse ) myHttpWebRequest.GetResponse();
        myHttpWebResponse.Cookies = myCookieContainer.GetCookies(myHttpWebRequest.RequestUri);
        myResponseStream = myHttpWebResponse.GetResponseStream();
        myStreamReader = new StreamReader(myResponseStream , Encoding.GetEncoding("gb2312"));
        outdata = myStreamReader.ReadToEnd();
        myStreamReader.Close();
        myRequestStream.Close();
        Console.WriteLine(outdata);
        //再次显示"登录" 
        //如果把*行注释调,就显示"没有登录" 
    }

如果我现在<iframe >标签中显示的系统网址为http://xxx.com,已知的用户名输入框name="uid",密码输入框name="password",我要输入的用户名为"aa",密码为"bb",我应该怎么做呢? --------------------编程问答-------------------- 另外我不需要登录进外部系统,只要在页面上将用户名和密码填上就行了,点击按钮的过程由用户自己进行 --------------------编程问答-------------------- cookie + token吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,