Click here to Skip to main content
14,983,064 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
hello,
i want pass data in $.ajax but when i run project i get null data in c# code and get
500 Internal Server Error in inspect element

my code is :
JavaScript
function refreshTime(options) {
            $.ajaxService({
                url: 'http://localhost:1549/Store/Pages/services.aspx?ServiceName=hello-world',
                data:{ oldpassword: $('#oldpassword').val(), newpassword: $('#newpassword').val() },
                onStartService: function () { $(options.target).addClass('loading'); },
                onEndService: function () { $(options.target).removeClass('loading'); },
                onResponse: function (response) {
                    if (response.result == '1') {
                        $.pushMessage({ message: 'success changed', messageClass: 'success-message', delay: 3000 });
                    }
                    else {
                        $.pushMessage({ message: 'error in change password', messageClass: 'success-message', delay: 3000 });
                    }
                }
            });
        }


C#
NameValueCollection ResponseResultCollection = new NameValueCollection();

protected void Page_Load(object sender, EventArgs e)
{
    System.Threading.Thread.Sleep(2200);
    string serviceName = this.Request.QueryString["ServiceName"];
    if (!string.IsNullOrEmpty(serviceName))
    {

        switch (serviceName.ToLower().Trim())
        {
            case ("hello-world"):
                string oldpassword = Request["oldpassword"].ToString();//i get null this
                string newpassword = Request["newpassword"].ToString();//and get null this
                try
                {

                    System.Web.Security.MembershipUser usr = System.Web.Security.Membership.GetUser();
                    if (usr.ChangePassword(oldpassword, newpassword))
                        ResponseResultCollection["result"] = "1";
                    else
                        ResponseResultCollection["result"] = "0";
                }
                catch (Exception ex) { Response.Write("An exception occurred: " + Server.HtmlEncode(ex.Message) + ". Please re-enter your values and try again."); }
                break;
        }
    }
    Response.Write(this.GenerateResponseResult());
    Response.End();
}

private string GenerateResponseResult()
{
    string result = "";

    foreach (string key in this.ResponseResultCollection.AllKeys)
    {
        result += string.Format(",\"{0}\":\"{1}\"", key, this.ResponseResultCollection[key]);
    }

    if (!string.IsNullOrEmpty(result))
    {
        result = result.Substring(1);
        result = "{" + result + "}";
    }

    return result.ToString();
}
Posted
Updated 13-Jan-21 3:48am
v2

Quote:
The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client. This is not related to client and the fault is in the webpage/website requested that resides on server. This status code can be considered as a ‘catch-all’ server error of Web server.



Quote:
Make sure that internally web server maintains some kind of internal error logs that gives more detail of what went wrong and thus help in diagnosing the issue. Generally, it is logged into Windows Event Logs on the server. Thus, first thing while troubleshooting the error is to see Windows Event Logs on the server to find what went wrong.

Other useful thing to troubleshoot it would be to disable friendly HTTP error messages to see if the raw content can provide a direction to look more. Steps:

Go to menu Tools/Internet Options in your IE.
Click on the Advanced tab & then uncheck “Show friendly HTTP error messages” option and then click OK.
Now, when on accessing the same web page, much more developer meaningful error message will be shown.

Moving on, following are most common:

Option #1: HRESULT: 0×80070035 – The page cannot be displayed because an internal server error has occurred. This occurs because the server that is running IIS cannot access the configured root directory of the requested location.

Resolution would be to make sure that the server that is running IIS can access the configured root directory of the requested location.

Option #2: HRESULT: 0x800700c1 – The page cannot be displayed because an internal server error has occurred. This occurs because a script mapping is not valid.

Resolution would be to make sure that the script mapping points to the ISAPI.dll file that can process the request. To do this, follow these steps:

Click Start, click Run, type inetmgr.exe, and then click OK.
In IIS Manager, expand server name, expand Web sites, and then click the Web site that you want to modify.
In Features view, double-click Handler Mappings.
Make sure that the script mapping points to the correct ISAPI.dll file. (e.g.: .asp files should map to the %windir%\system32\inetsrv\asp.dll file)

Option #3: HRESULT: 0x8007007f – There is a problem with the resource you are looking for, so it cannot be displayed. This occurs because the handler mapping for the requested resource points to a .dll file that cannot process the request.

Resolution would be to edit the handler mapping for the requested resource to point to the .dll file that can process the request. To do this, follow these steps:

Click Start, click Run, type inetmgr.exe, and then click OK.
In IIS Manager, expand server name, expand Web sites, and then click the Web site that you want to modify.
In Features view, double-click Handler Mappings.
Right-click the script mapping that you want to edit, and then click Edit.
In the Edit Script Map dialog box, type the appropriate executable file in the Executable box, and then click OK.

Option #4: One of the other possibilities could be an issue in the way web application is hosted. Some security configuration issue or conflict due to multiple config files.

Resolution would be to make sure application is hosted correctly by published the application as website and setting up the virtual directory as needed.


for more details:
HTTP 500 – Internal server error[^]
   
v2
Comments
SadeqHatami 15-Sep-13 14:49pm
   
thank's for your help, but this solution don't solved my problem :(
Mehdy Moini 16-Sep-13 2:50am
   
didn't change your error message?
did you follow the steps?
SadeqHatami 16-Sep-13 2:53am
   
no my error dont' change,
yes i do it :(
i involved in a few days for this problem,i have been overwhelmed
Mehdy Moini 16-Sep-13 3:18am
   
call your url, directly without ajax and check if problem is related to your client code or server code, if error is still exists , zoom on your server code
SadeqHatami 16-Sep-13 3:45am
   
i call url directly, and url is worked,
It is interesting that url in ajax is pass to services.cs and get this,but can't get data value
Mehdy Moini 16-Sep-13 6:16am
   
$('#newpassword').val() , are you sure about its value?,
once i had two element with same id and it cause same problem.
SadeqHatami 16-Sep-13 6:24am
   
yes i'm sure,
please see this:
http://i.cubeupload.com/1NbpFg.png

http://i.cubeupload.com/hOidkl.png
Mehdy Moini 16-Sep-13 6:35am
   
I found your picture error Sadegh jan, i think , if you are sure about your value in client layer, you should profile it with a sniffer and find where the value changes
SadeqHatami 16-Sep-13 6:27am
   
yes, i'm sure ,
please see this:
http://i.cubeupload.com/1NbpFg.png

http://i.cubeupload.com/hOidkl.png

i used StreamReader but this is empty too! :(
Mehdy Moini 16-Sep-13 6:41am
   
profile your data with fiddler and find where you lose it:
http://fiddler2.com/get-fiddler
SadeqHatami 16-Sep-13 8:48am
   
thank's for your hand, i found problem
Mehdy Moini 16-Sep-13 12:32pm
   
very good, is it possible to tell me about problem?
SanSkun 13-Jul-15 5:55am
   
Hey SadeqHatami,I am facing same issue can u plz tell what is issue and how to solve it. Plzz
SanSkun 13-Jul-15 5:56am
   
Hi SadeqHatami, How to fix this issue. I am also facing same here.Please let me know.
bhargavvenkatesh 3-Nov-18 7:05am
   
Hi I am getting the same error in my php application. Is there any solution for this
Member 14373994 16-May-19 5:47am
   
Hi, Failed to load resource: the server responded with a status of 500 (Internal Server Error) this is my error, and I couldn't solve it, please help me ......
Hi, I had similar result, but my problem was solved just refreshing my entities/adding what my controllers need it. One of them didn´t have a stored procedure that was called. Hope this helps someone scratching his head.
   
Comments
Patrice T 11-Jul-18 18:08pm
   
5 years too late
jstock32 3-Aug-20 19:39pm
   
thank you...you just saved me a ton of time...refreshing my entities worked by flushing out some db fields that I forgot had been updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900