Whenever i try to put or delete method using webapi, it returns 500 internal error! It only allows get and Post method:
I googled all over few days! what i found to change or add <remove name="WebDAV"/>
this tag in <system.webServer>
.I did but not worked!
I also tried 1.Go to IIS Manager.
2.Click on your app.
3.Go to "Handler Mappings".
4.In the feature list, double click on "WebDAV".
5.Click on "Request Restrictions".
6.In the tab "Verbs" select "All verbs" .
7.Press OK.
found on IIS 7.5 + enable PUT and DELETE for RESTFul service, extensionless
Everything works in godaddy shared hosting but VPS that i recently got!
My JS: POST
$http.post("/api/ProductsApi/InsertCompanydata/", addCompanyData)
.then(function (data) {
$scope.saveOrUpdateSuccessTxt = 'Successfully Saved!';
}).catch(function (e) {
}).then(function () {
$scope.saveOrUpdateLoading = false;
});
Put:
$http.put("/api/ProductsApi/UpdateCompany/" + $scope.CompanyID, editCompanyData)
.then(function (data) {
$scope.saveOrUpdateSuccessTxt = 'Successfully Updated!';
}).catch(function (e) {
console.log(e.status)
}).then(function () {
$scope.saveOrUpdateLoading = false;
});
API Controller::
[HttpPost]
[Route("api/ProductsApi/InsertCompanydata")]
public HttpResponseMessage InsertCompanydata(Companyt com)
{
using (SqlCommand command = con.CreateCommand())
{
command.CommandText = "INSERT into Companyt (CompanyName) values (@name)";
command.Parameters.AddWithValue("@name", com.CompanyName);
//compare CompanyName
SqlCommand com2 = new SqlCommand("sp_CompanyInsertValidation", con);
com2.CommandType = CommandType.StoredProcedure;
com2.Parameters.Add(new SqlParameter("@CompanyName", com.CompanyName));
SqlDataAdapter da = new SqlDataAdapter(com2);
DataSet ds = new DataSet();
da.Fill(ds);
int m = ds.Tables[0].Rows.Count;
if (m >= 1)
{
return Request.CreateResponse(HttpStatusCode.Conflict);
}
else
{
con.Open();
command.ExecuteNonQuery();
con.Close();
}
}
return Request.CreateResponse(HttpStatusCode.OK);
}
[HttpPut]
[Route("api/ProductsApi/UpdateCompany")]
public HttpResponseMessage UpdateCompany(int id, Companyt comp)
{
using (SqlCommand command = con.CreateCommand())
{
command.CommandText = "UPDATE Companyt SET CompanyName = @name where CompanyID =@id";
command.Parameters.AddWithValue("@name", comp.CompanyName);
command.Parameters.AddWithValue("@id", id);
//compare CompanyName
SqlCommand com = new SqlCommand("sp_CompanyUpdateValidation", con);
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(new SqlParameter("@name", comp.CompanyName));
com.Parameters.Add(new SqlParameter("@id", id));
SqlDataAdapter da = new SqlDataAdapter(com);
DataSet ds = new DataSet();
da.Fill(ds);
int m = ds.Tables[0].Rows.Count;
con.Open();
command.ExecuteNonQuery();
con.Close();
}
return Request.CreateResponse(HttpStatusCode.OK);
}
My webconfig portion:
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
<add key="owin:AppStartup" value="IdentitySample.Startup,Inventory" />
<add key="webpages:Version" value="3.0.0.0" />
</appSettings>
<system.web>
<!--<compilation debug="true" targetFramework="4.5" />-->
<!--<httpRuntime targetFramework="4.5"/>
-->
<!--<trust level="Full" originUrl=""/>-->
<!--
<trust level="Full" originUrl=""/>
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880"/>
</authentication>-->
<sessionState mode="InProc" timeout="2880" cookieless="false"></sessionState>
<!--<compilation debug="true" targetFramework="4.5" />-->
<httpRuntime targetFramework="4.5" />
<!--<trust level="Full" originUrl=""/>-->
<trust level="Full" originUrl="" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" slidingExpiration="true" timeout="2880" />
</authentication>
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<machineKey validationKey="1A4DBAA59CCB4BFCEA0CB3485D7809F6E7382E4E7877EDAA26B6A9310A95B659DA061232F757C8F973D24D3EBA4DBC1D08F4E5AC5C1E65454C5150AA49E1C7AC" decryptionKey="F4A8287B30C5596AD89258E31D3F53D078492EF596898BB87A14EBB32FF79968" validation="SHA1" decryption="AES" />
<httpHandlers>
<add verb="*" path="routes.axd" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</httpHandlers>
<customErrors mode="Off" defaultRedirect="~/default.aspx">
<error statusCode="500" redirect="~/500.aspx" />
<error statusCode="404" redirect="~/404.aspx" />
<error statusCode="403" redirect="~/403.aspx" />
</customErrors>
<compilation debug="true" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="RoleManager" />
<remove name="WebDAVModule" />
<!-- add this -->
</modules>
<validation validateIntegratedModeConfiguration="false" />
<!--<handlers>
<remove name="WebDAV"/>
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web"/>
<remove name="ExtensionlessUrlHandler-Integrated-4.0"/><remove name="OPTIONSVerbHandler"/>
<remove name="TRACEVerbHandler"/>
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
</handlers>-->
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
<remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
<add name="AttributeRouting" path="routes.axd" verb="*" type="AttributeRouting.Web.Logging.LogRoutesHandler, AttributeRouting.Web" />
</handlers>
<staticContent>
<remove fileExtension=".woff" />
<mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
<remove fileExtension=".woff2" />
<mimeMap fileExtension=".woff2" mimeType="application/font-woff2" />
</staticContent>
</system.webServer>