पर ASP.NET वेबएपीआई और डेटाबेस के साथ काम नहीं कर रहा है और हटाएं मैं मूल सीआरयूडी संचालन के साथ एएसपी.NET वेबएपीआई प्रोजेक्ट पर काम कर रहा हूं। यह परियोजना स्थानीय रूप से चलती है और इसमें विंडोज़ एज़ूर के अंदर एक नमूना डेटाबेस रहता है।विंडोज एज़ूर
अब तक, एचटीपी जीईटी और पोस्ट ठीक काम करता है, मुझे 200 और 201 दे रहा है। लेकिन मैं डेली और पोस्ट के साथ संघर्ष कर रहा हूं। मैंने Web.config में हैंडलर को बदल दिया, वेबडाव हटा दिया, लेकिन इनमें से कोई भी काम नहीं किया। सीओआरएस को सक्षम करने और [AcceptVerbs] जैसे सभी प्रकार के गुण काम नहीं कर पाए।
कोई विचार क्या मैं गलत कर रहा हूं?
फ़िडलर कच्चे आउटपुट:
HTTP/1.1 405 Method Not Allowed
Cache-Control: no-cache
Pragma: no-cache
Allow: GET
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-AspNet-Version: 4.0.30319
X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcTWFyY1xPbmVEcml2ZVxEb2t1bWVudGVcRmlcVnNQcm9qZWt0ZVxONTIwMTQwODI1XE41XE41XGFwaVxwcm9kdWN0XDEwODM=?=
X-Powered-By: ASP.NET
Date: Sun, 14 Sep 2014 15:00:43 GMT
Content-Length: 75
{"Message":"The requested resource does not support http method 'DELETE'."}
Web.config:
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<remove name="WebDAVModule" />
</modules>
<handlers>
<remove name="WebDAV" />
<remove name="ExtensionlessUrlHandler-Integrated-4.0" />
<add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT" type="System.Web.Handlers.TransferRequestHandler" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
</handlers>
</system.webServer>
नियंत्रक:
public class ProductController : BaseApiController
{
public ProductController(IRepository<Product> repo)
: base(repo)
{
}
[HttpGet]
public IEnumerable<Product> Get()
{
//...
}
[HttpGet]
public Product Get(int id)
{
//...
}
[HttpPost]
public HttpResponseMessage Post([FromBody] Product product)
{
//...
}
[HttpPut]
public HttpResponseMessage Put(int productId, [FromBody] Product product)
{
//..
}
[HttpDelete]
public HttpResponseMessage Delete(int productId)
{
//..
}
}
रूटिंग & formatters:
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Configure Web API to use only bearer token authentication.
config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));
config.Routes.MapHttpRoute(
name: "Product",
routeTemplate: "api/product/{id}",
defaults: new {controller = "product", id = RouteParameter.Optional }
);
// Custom Formatters:
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(
config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml"));
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
}
}
आप विशेषता रूटिंग क्यों कॉल कर रहे हैं लेकिन आप मार्ग को कॉन्फ़िगर करने के पूर्व WebApi2 तरीके का उपयोग करके उत्पाद मार्ग कॉन्फ़िगर करते हैं? –
यह एक बचे हुए है और वहां नहीं होना चाहिए। मैं इसे अद्यतन करता हूँ। thx – oldsport