如何将数据从Windows应用程序传递到Web应用程序?

时间:2013-11-29 11:51:05

标签: c# asp.net winforms

我有一个Windows应用程序,我想从这个Windows应用程序打开我的Web应用程序。我的Windows应用程序将在授权后生成密钥和机器代码,并将密钥和机器代码保存到活动用户之间的数据库中。现在我想将此密钥发送到浏览器,以便我的Web应用程序可以使用他的机器识别用户 我怎么能这样做?
我无法使用URL,因为用户将能够复制URL并从另一台计算机使用我的Web应用程序。我必须限制它 还有其他方法吗?

3 个答案:

答案 0 :(得分:0)

您可以使用c#

发布数据

http://msdn.microsoft.com/en-us/library/debx8sh9(v=vs.110).aspx

另请参阅stackoverflow中的这篇文章

How to post data to a website

答案 1 :(得分:0)

您可以编写一个ashx处理程序,并从您的Windows应用程序传递您的数据(或对您的数据的一些引用)。以下是如何完成此操作的示例:

how to call ASHX handler and getting the result back

答案 2 :(得分:0)

将winform数据传输到Web应用程序有两种方法

如果要将数据传输到IE,则可以使用

1)MSHtml.dll

<强>码

InternetExplorer TargetIE = null;
IHTMLDocument2 document = null;
//Check whether the IE is opened
foreach (InternetExplorer internetExplorer in new ShellWindows())
{
  if (internetExplorer.Document is HTMLDocument)
      {
        TargetIE = internetExplorer;
        break;
      }
}

2)如果您想将数据从winform传输到任何网页浏览器,我个人建议您使用selenium。 从此站点help

下载相应驱动程序的相应DLL和驱动程序

代码

using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Support.UI;
using OpenQA.Selenium.Chrome;

namespace WindowsFormsChrome
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // download the chrome driver
            IWebDriver driver = new ChromeDriver(@"C:\Users\Downloads\chromedriver"); 
            driver.Navigate().GoToUrl("http://www.yahoo.com");
            IWebElement myField = driver.FindElement(By.Id("txtUserName"));
            myField.SendKeys("UserName");
            IWebElement myField = driver.FindElement(By.Id("txtPassword"));
            myField.SendKeys("Password");
            IWebElement myField = driver.FindElement(By.Id("btnLogin"));
            myField.click()
        }
     }
}

这第二部分适用于所有浏览器,您只需根据需要替换chromeDriver类。