Reputation: 21
The website works locally but on the server it doesn't.
I am using free hosting somee.com
Site link: http://multiple-search.somee.com/
This site takes search queries from textbox and searches it in google, yahoo, etc. I received an error message when entering searchqueries and pushing a button. The error is:
[Win32Exception (0x80004005): Access is denied]
System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) +614
System.Diagnostics.Process.Start() +56
System.Diagnostics.Process.Start(ProcessStartInfo startInfo) +49
System.Diagnostics.Process.Start(String fileName) +31
_Default.Button1_Click(Object sender, EventArgs e) +159
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
How can I eliminate this error? My code is:
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
// Getting Text from textbox
string input = TextBox1.Text;
//Parsing criteria: New Line
string[] lines = input.Split('\n');
foreach (string ln in lines)
{
if (CheckBox1.Checked == true)
{
System.Diagnostics.Process.Start("https://www.google.com/#q=" + ln.Substring(0));
}
if (CheckBox2.Checked==true)
{
System.Diagnostics.Process.Start("http://search.yahoo.com/search;_ylt=AmGbBTVg4RHlgJHNOZ4AaA2bvZx4?p=" + ln.Substring(0) + "&toggle=1&cop=mss&ei=UTF-8&fr=yfp-t-900");
}
if (CheckBox3.Checked == true)
{
System.Diagnostics.Process.Start("http://www.bing.com/search?q=" + ln.Substring(0) + "&go=&qs=n&form=QBLH&pq=chris+brown&sc=8-11&sp=-1&sk=");
}
if (CheckBox4.Checked == true)
{
System.Diagnostics.Process.Start("http://www.ask.com/web?q=" + ln.Substring(0) + "&search=&qsrc=0&o=0&l=dir");
}
if (CheckBox5.Checked == true)
{
System.Diagnostics.Process.Start("http://search.aol.com/aol/search?s_chn=prt_ct9&enabled_terms=&s_it=comsearch50ct17&q=" + ln.Substring(0));
}
}
}
}
Upvotes: 0
Views: 892
Reputation: 1474
Running a process on the server is not allowed. For server-side code, try this instead although it will only open one window rather than all the search:
Server.Transfer("https://www.google.com/#q=" + ln); // for Google
For multiple windows/tabs to open, I would look into client-side JavaScript code instead. Alternatively, you can get the results from Google/Bing etc. using their APIs and merge them together as described in @Paul Zahra's answer.
Upvotes: 0
Reputation: 9725
The error description is: [Win32Exception (0x80004005): Access is denied]
This is an access permissions issue. To fix it you can give admin access to the IIS user. Although that is not a good solution.
A better solution would be to run the application pool under a user that has permission to run an executable, preferably a not an admin level user.
You would be better off not starting up browsers but using each search engines API to get search results and display them accordingly.... take a look at this tutorial on how to use GOOGLE and BINGs API
Upvotes: 1
Reputation: 2398
I agree with Alex that your host is likely restricting starting a new Process. Most hosting services will refuse to allow access to what is essentially starting a new application on their server.
Aside from that, your code won't work anyway. Even if they allowed the starting of a new process, the client will never see the results. This would open new browser windows on the server, not on the client machine.
Upvotes: 1
Reputation: 332
As others said, System.Diagnostics.Process
might be restricted. Try to do it in a different way for example using System.Net.Http.HttpClient
.
Upvotes: 0
Reputation: 355
The user account being used by IIS in the AppPool doesn't have permissions to start new processes. When running locally that account is probably an administrator or at least user level account.
Upvotes: 0
Reputation: 96596
Process.Start()
starts a process on the server. This works as long as the web app is running on your machine, but is certainly restricted in a hosted environment.
Upvotes: 0
Reputation: 38529
I suspect a restriction on your hosting is preventing
System.Diagnostics.Process.Start
Upvotes: 2