locked
Getting Intrenal server error after hosting web api to IIS 7 RRS feed

  • Question

  • User592594220 posted

    Hi,

    I am new to Web api. I have design a web api having Post method which update the value in database through entiety framework. I have configured the DB connection string for windows authentication as only I have the access to Databse. I have tested this in visual studio and it is working fine. when I have hosted the same in IIS on same server,  and try to access it using Jquery, I am getting an error as "No Transport". I have tested it using fiddler and I am getting more descriptive error message which says "500 Internal Server error Login failed for user <machine name>". So I have add Identity impersonation in Web.config of web API and impersonate my windows account but still getting the same error. please advice me how to solve this issue.

    Web.config 
      <identity impersonate="true" userName="*******" password="********"/>
      <authentication mode="Windows">
    
    
    Web API Controller 
    [ResponseType(typeof(UACTbf5360e8487d4e3e82ccccb494d09623))]
            [HttpPost]
            [AcceptVerbs("POST")]
            public IHttpActionResult PostUpdateContract([FromBody] UACTbf5360e8487d4e3e82ccccb494d09623 Cont)
            {
                //if (!ModelState.IsValid)
                //{
                //    return BadRequest(ModelState);
                //}
    
                UACTbf5360e8487d4e3e82ccccb494d09623 _Contract;
                bool flag = false;
                using (var ctx = new ContractEntities())
                {
                    _Contract = ctx.UACTbf5360e8487d4e3e82ccccb494d09623.Where(c => c.fldId == Cont.fldId).FirstOrDefault<UACTbf5360e8487d4e3e82ccccb494d09623>();
                    if (_Contract != null)
                    {
                        try
                        {
                            _Contract.AssignedTo = Cont.AssignedTo;
                            _Contract.MemberfldId = Cont.MemberfldId;
                            _Contract.MemberMember = Cont.MemberMember;
                            ctx.Entry(_Contract).State = System.Data.Entity.EntityState.Modified;
                            ctx.SaveChanges();
                            flag = true;
                        }
                        catch (Exception ex)
                        {
                            flag = false;
                        }
                        if(flag)
                            return StatusCode(HttpStatusCode.OK);
                        else
                            return StatusCode(HttpStatusCode.ExpectationFailed);
                      
                    }
                    else
                    {
                        return StatusCode(HttpStatusCode.NotFound);
                    }
    
                }
    
               
                
            }
    
    Jquery call
    
       <script>
            $(document).ready(function () {   
                
                var Contract = {
                    AssignedTo :"CCA Team new",
                    MemberfldId :"1",
                    MemberMember :"ABC",
                    fldId:"1"
                }
              
                $("#Save").click(function () {
                    $.ajax({
                        url:'http://localhost:9810/api/Contract',
                        type:'POST',                                       
                        data:JSON.stringify(Contract),
                        contentType:"application/json",
                        success:function (data, textStatus, xhr) {
                            alert("success:- " + data);
                        },
                        error: function (xhr, textStatus, errorThrown) {
                            alert('Error ' + errorThrown +' '+ xhr);
                        }
                    });
                });
            });
        </script>
    
    
    

    Tuesday, August 4, 2015 4:01 AM

Answers

  • User592594220 posted

    Hi,

    I have change the appliation pool to run with my credential and now I am able to get responce from Web api. I called the Post method using Fiddler and it is working fine. To solve the No transport error which I was getting when calling the WEB API from Jquery I have addedd CrossDomain: false in Jquery ajax call and solve the issue. Below is updated Jquery call

    Jquery call

       <script>
            $(document).ready(function () {  
               
                var Contract = {
                    AssignedTo :"CCA Team new",
                    MemberfldId :"1",
                    MemberMember :"ABC",
                    fldId:"1"
                }
             
                $("#Save").click(function () {
                    $.ajax({
                        url:'http://localhost:9810/api/Contract',
                        type:'POST',                                      
                        data:JSON.stringify(Contract),
                        contentType:"application/json",

    CrossDomain: false,
                        success:function (data, textStatus, xhr) {
                            alert("success:- " + data);
                        },
                        error: function (xhr, textStatus, errorThrown) {
                            alert('Error ' + errorThrown +' '+ xhr);
                        }
                    });
                });
            });
        </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 5, 2015 2:13 AM

All replies

  • User592594220 posted

    Hi,

    I have change the appliation pool to run with my credential and now I am able to get responce from Web api. I called the Post method using Fiddler and it is working fine. To solve the No transport error which I was getting when calling the WEB API from Jquery I have addedd CrossDomain: false in Jquery ajax call and solve the issue. Below is updated Jquery call

    Jquery call

       <script>
            $(document).ready(function () {  
               
                var Contract = {
                    AssignedTo :"CCA Team new",
                    MemberfldId :"1",
                    MemberMember :"ABC",
                    fldId:"1"
                }
             
                $("#Save").click(function () {
                    $.ajax({
                        url:'http://localhost:9810/api/Contract',
                        type:'POST',                                      
                        data:JSON.stringify(Contract),
                        contentType:"application/json",

    CrossDomain: false,
                        success:function (data, textStatus, xhr) {
                            alert("success:- " + data);
                        },
                        error: function (xhr, textStatus, errorThrown) {
                            alert('Error ' + errorThrown +' '+ xhr);
                        }
                    });
                });
            });
        </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, August 5, 2015 2:13 AM
  • User438962230 posted

    Glad you've made it.

    Thursday, August 6, 2015 11:30 PM