从Windows服务打开MVC4网页

从Windows服务打开MVC4网页

本文介绍了从Windows服务打开MVC4网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Database: MySQL MVC4 Web Application run on IIS Locally Windows Service

I have written a Windows Service to automatically Log data from few Machines and save it into Database. Its working fine, But i have a senario where one machine data will be logged and saved to database and after that i need to open a MVC4 webpage(specific url) from windows service by passing primary key of that table as parameter.

WebPage consists of 2 textboxes.

I am able to achieve this task in Windows forms with the same code but i unable to do it in Windows service.i am not getting any error data is getting logged and saving into database and but its not opening webpage.





这是我的代码:



Here is my Code:

try
            {
                int id = 0;
                String sql1c = "SELECT WeighID FROM weighing_scales_tbl WHERE MachineID = " + machid + " AND GroupWt = '" + weigh + "'  ORDER BY InsertedDate DESC";
                MySqlDataAdapter da1c = new MySqlDataAdapter(sql1c, mc.msqlConnection);
                DataTable dt1c = new DataTable();
                da1c.Fill(dt1c);
                if (dt1c.Rows.Count != 0)
                {
                    id = Convert.ToInt32(dt1c.Rows[0][0]);
                }

                StreamWriter str = new StreamWriter("D:\\Popup.txt", true);

                str.WriteLine("Popup Exception on : " + DateTime.Now.ToString() + "\n " );

                str.Close();
                 ProcessStartInfo startInfo = new ProcessStartInfo("chrome.exe");
                startInfo.WindowStyle = ProcessWindowStyle.Minimized;

                //Process.Start(startInfo);

                StreamWriter str1 = new StreamWriter("D:\\Popup.txt", true);

                str1.WriteLine("Popup Starts on : " + DateTime.Now.ToString() + "\n ");

                str1.Close();

                startInfo.Arguments = "http://localhost:4113/LooseShot/AddLooseshot/" + id + "";

                StreamWriter str2 = new StreamWriter("D:\\Popup.txt", true);

                str2.WriteLine("Popup open on : " + DateTime.Now.ToString() + "\n ");

                str2.Close();

                Process.Start(startInfo);


                //System.Diagnostics.Process.Start("http://localhost:4113/LooseShot/AddLooseshot/" + id + "");
            }
            catch (SocketException se)
            {
                StreamWriter str = new StreamWriter("D:\\Popup.txt", true);

                str.WriteLine("Popup Exception on : " + DateTime.Now.ToString() + "\n " + se.Message);

                str.Close();
            }

推荐答案


这篇关于从Windows服务打开MVC4网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:30