问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Xml;usingmshtml;namespaceWindowsApplication1{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();textBox_url.Text="http://bbs.jznews.com.cn/portal.php";InitListView();LoadUserData();}//privatevoidherfclick(stringurl)//{//for(inti=0;i<webBrowser1.Document.All.Count;i++)//{//if(webBrowser1.Document.All[i].TagName=="A"&&webBrowser1.Document.All[i].GetAttribute("href").ToString().Trim()==url)//{//webBrowser1.Document.All[i].InvokeMember("click");//引发”CLICK”事件//break;//}//}//}privatevoidwebBrowser1_DocumentCompleted(objectsender,WebBrowserDocumentCompletedEventArgse){webBrowser1.ScriptErrorsSuppressed=true;if((e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/portal.php"))//登陆页面||(e.Url.ToString().ToLower().Equals(""))){HtmlElementtextboxUserId=this.webBrowser1.Document.GetElementById("ls_username");//如果没有ID,用Name获取//HtmlElementtextboxUserId=this.webBrowser1.Document.All["登录用户名文本框的Name"];HtmlElementtextboxPassword=this.webBrowser1.Document.GetElementById("ls_password");//如果没有ID,用Name获取//HtmlElementtextboxPassword=this.webBrowser1.Document.All["登录密码框的Name"];//HtmlElementbuttonSubmit=this.webBrowser1.Document.GetElementById("ls_cookietime");//如果没有ID,用Name获取//HtmlElementbuttonSubmit=this.webBrowser1.Document.All["ls_cookietime"];for(inti=this.listView_usr.SelectedItems.Count-1;i>=0;i--){ListViewItemitem=this.listView_usr.SelectedItems[i];//this.listView_usr.Items.Remove(item);stringstrUsr=item.SubItems[0].Text;stringstrPwd=item.SubItems[1].Text;textboxUserId.InnerText=strUsr;//填写帐号textboxPassword.InnerText=strPwd;//填写密码}//触发登录事件HtmlElementCollectionelements=this.webBrowser1.Document.GetElementsByTagName("button");//Request.ServerVariables("HTTP_REFERER");foreach(HtmlElementiteminelements){if(item.GetAttribute("className").Equals("pnvm")&&item.GetAttribute("type").Equals("submit")){//continue;item.InvokeMember("click");}//elseif(item!=textBox_url.Text)//{//item.InvokeMember("click");//}}}//elseif((e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/portal.php"))//||(e.Url.ToString().ToLower().Equals("http://bbs.jznews.com.cn/")))//{//HtmlElementCollectionlinks=webBrowser1.Document.Links;//foreach(HtmlElementlinkinlinks)//{//if(null==link.InnerText)//{//continue;//}//if(link.InnerText.Equals(""))//{//link.InvokeMember("click");//激发链接的点击事件//}//}//}}privatevoidwebBrowser1_NewWindow(objectsender,CancelEventArgse){e.Cancel=true;//取消使用系统的IE打开超链接webBrowser1.Navigate((senderasWebBrowser).Document.ActiveElement.GetAttribute("href"));//继续在窗体中打开页面}privatevoidwebBrowserQuit(){if(null==webBrowser1.Document){return;}webBrowser1.Document.Cookie="";HtmlElementCollectionlinks=webBrowser1.Document.Links;if(null==links){return;}foreach(HtmlElementlinkinlinks){if(null==link.InnerText){continue;}if(link.InnerText.Equals("退出")){link.InvokeMember("click");//激发链接的点击事件break;}}}privatevoidbutton1_Click(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();//if(null==webBrowser1.Url)//{webBrowser1.Url=newUri(textBox_url.Text);//}}}privatevoidInitListView(){listView_usr.GridLines=true;listView_usr.FullRowSelect=true;listView_usr.View=View.Details;listView_usr.Scrollable=true;listView_usr.MultiSelect=false;listView_usr.HeaderStyle=ColumnHeaderStyle.Nonclickable;listView_usr.Columns.Add("用户名",100,HorizontalAlignment.Right);listView_usr.Columns.Add("密码",100,HorizontalAlignment.Left);}privatevoidLoadUserData(){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);XmlNodeListnewXMLNodes=XMLDom.SelectNodes("/users/user");listView_usr.Items.Clear();foreach(XmlElementxninnewXMLNodes){//XmlElement*pstElememt=(XmlElement*)&XmlNode;stringstrId=xn.GetAttribute("id");stringstrPwd=xn.GetAttribute("pwd");ListViewItemli=newListViewItem();li.SubItems.Clear();li.SubItems[0].Text=strId;li.SubItems.Add(strPwd);listView_usr.Items.Add(li);//MessageBox.Show(title);}}privatevoidlistView_usr_SelectedIndexChanged(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();webBrowser1.Url=newUri(textBox_url.Text);}}privatevoidlistView_usr_DoubleClick(objectsender,EventArgse){if(""!=textBox_url.Text){webBrowserQuit();if(null==webBrowser1.Url){webBrowser1.Url=newUri(textBox_url.Text);}}}privatevoidbutton_addusr_Click(objectsender,EventArgse){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);XmlElementtheUser=XMLDom.CreateElement("user");theUser.SetAttribute("id",textBox_usr.Text);theUser.SetAttribute("pwd",textBox_pwd.Text);XMLDom.DocumentElement.AppendChild(theUser);XMLDom.Save(strPath);LoadUserData();}privatevoidbutton_delusr_Click(objectsender,EventArgse){XmlDocumentXMLDom=newXmlDocument();stringstrPath=System.Environment.CurrentDirectory+"/user.xml";XMLDom.Load(strPath);for(inti=this.listView_usr.SelectedItems.Count-1;i>=0;i--){ListViewItemitem=this.listView_usr.SelectedItems[i];//this.listView_usr.Items.Remove(item);stringstrUsr=item.SubItems[0].Text;stringstrItemPath="/users/user[@id=""+strUsr+""]";XmlElementtheUser=(XmlElement)XMLDom.SelectSingleNode(strItemPath);if(null!=theUser){theUser.ParentNode.RemoveChild(theUser);}}XMLDom.Save(strPath);LoadUserData();}privatevoidForm1_Load(objectsender,EventArgse){}}}
解决方案
解决方案二:
navigationURl="javascript:parent.location.href='../Login.aspx'"或者top.location.href='地址'
解决方案三:
不需要做判断吗
解决方案四:
防盗链对吧usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSystem.Web.Mvc;usingSystem.Web.Security;namespaceHRMS.Controllers{///<summary>///防盗链(Filter)///</summary>publicclassMyFilter:ActionFilterAttribute{publicoverridevoidOnActionExecuted(ActionExecutedContextfilterContext){//base.OnActionExecuted(filterContext);varuser=filterContext.HttpContext.Session["user"];if(user==null){filterContext.HttpContext.Response.Write("<script>alert('请登陆...')</script>");//获取刚刚用户浏览的URL(不指定参数值)stringurl=FormsAuthentication.DefaultUrl;filterContext.HttpContext.Response.Write("<script>window.parent.location.assign('"+url+"')</script>");}}}}//用法[类名(就是放上面源代码的类名)]publicresultactionXX(){...}
解决方案五:
饿4楼的大哥,你这步是我想要的答案啊,我是要在我所发的代码上进行的。也就是说,要登录后返回当前浏览的页面,我这是获取的别人的论坛,要自动登录,还要是在所浏览的当前页面登录,并且返回当前的浏览页面。你这个没用。我这个不是网站,是应用程序。
解决方案六:
郁闷啊,谁能解决下这个问题,在线等了一天没人会?
解决方案七:
现在这个能登陆吗
解决方案八:
可以登录,就是无法返回当前浏览页,只能返回默认的页面。
解决方案九:
该回复于2011-12-09 09:12:57被版主删除