c# - Web API 2 not working (404) -
I have been trying long time Web API 2 is working. I have read a lot of articles and posts on the Internet, But till now I have been inauspicious.
I just need to work as a simple web API method, but for some reason I have not yet received 404 method. I really do not know now where the problem can be, because I think everything is fine.
I have tried many features, configurations and so many changes. I end up with this code:
Global.asax
Regional Registration. Registrar AllAreas (); FilterConfig.RegisterGlobalFilters (GlobalFilters.Filters); RouteConfig.RegisterRoutes (RouteTable.Routes); GlobalConfiguration.Configure (WebApiConfig.Register); WebApiConfig.cs
config.MapHttpAttributeRoutes (); Config.routes.MapHttpRoute (Name: "DefaultApi", Margaemplate: "API / {Administrator} / {ID}", default: new {id = RouteParameter.Optional}); Var app xml type = config.formatters.xmlFormatter.SupportedMediaTypes.FirstOrDefault (x = & gt; x.MediaType == "app / xml"); Config.formatters.xmlFormatter.SupportedMediaTypes.Remove (appXmlType); Public class ContactFormController: ApiController {[root ( "~ / api / sendemail")] [http post ()] public IHttpActionResult SendEmail (ContactFormModel) Contact Form) {OK OK (); }}
Model:
Public category ContactFormModel {public string name {get; Set; } Public String Email {get; Set; } Public string theme {get; Set; } Public string message {get; Set; }} jquery code
var jsonData = {"name": name.val (), "email": email.val (), " Subject ": subject.val ()," message ": comment.val ()}; $ .ajax ({url: "API / Sent email", type: "post", data: jssadata, cache: incorrect, ...}); As you can see, this is MVC 5 + Web API2.
Thank you for the help is a simple thing and nothing is working.
Please update your global .sax here:
protected Zero application_Start () {Area registration. Registrar All Ares (); GlobalConfiguration.Configure (WebApiConfig.Register); FilterConfig.RegisterGlobalFilters (GlobalFilters.Filters); RouteConfig.RegisterRoutes (RouteTable.Routes); } [Root ("/ api / sendemail")] and [root ("~ / api / sendemail"]] >
Comments
Post a Comment