简体   繁体   中英

ASPX website works locally, but not on the server

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));
            }
        }
    }
}

我怀疑您对主机的限制阻止了

System.Diagnostics.Process.Start

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

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.

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.

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.

As others said, System.Diagnostics.Process might be restricted. Try to do it in a different way for example using System.Net.Http.HttpClient .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM