iis - WebApi Http requests returning 404 -
i using webapi 2 .net framework 4.5 building api , iis(7.5 integrated) , iis(8 integrated) deployment local , live environments.
i using system.web.http.cors cross domain requests.
webapi.config
public static void register(httpconfiguration config) { var cors = new enablecorsattribute("*", "*", "*"); config.enablecors(cors); config.maphttpattributeroutes(); config.filters.add(new unhandledexceptionfilterattribute()); config.bindparameter(typeof(datetime), new datetimemodelbinder()); }
authentication resource
[datacontract] public class authentication : baseresource { public authentication() { } [datamember(emitdefaultvalue=false)] public string username { get; set; } [datamember(emitdefaultvalue = false)] public string password { get; set; } }
authentication controller
[routeprefix("sessiontoken")] public class authenticationcontroller : apicontrollerbase { private readonly iauthenticationmanager _authenticationmanager; authenticationcontroller() { } public authenticationcontroller(iauthenticationmanager authenticationmanager) : base(authenticationmanager) { _authenticationmanager = authenticationmanager; } [httppost] [route("")] public httpresponsemessage post(authen.authentication auth) { auth = _authenticationmanager.createpermanenttoken(auth); return request.createresponse<authen.authentication>(httpstatuscode.created, auth); } }
web.config (iis 8 integrated mode)
<system.webserver> <validation validateintegratedmodeconfiguration="false" /> <modules runallmanagedmodulesforallrequests="false"> <remove name="webdavmodule" /> </modules> <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" /> </handlers> </system.webserver>
routeconfig
public class routeconfig { public static void registerroutes(routecollection routes) { routes.ignoreroute("{resource}.axd/{*pathinfo}"); routes.maproute( name: "default", url: "{controller}/{action}/{id}", defaults: new { controller = "home", action = "index", id = urlparameter.optional } ); } }
i trying perform post request, request returns 404. have tried configuration changes mentioned in of posts.
http request
url: http://api.x.com/sessiontoken
request headers
accept: application/json accept-encoding: gzip, deflate accept-language: en-us,en;q=0.8 connection: keep-alive content-length: 0 content-type: application/json host: api.x.com origin: http://x.com referer: http://x.com/
similar changes on local iis(7.5 integrated) work without hassle. same change not work on shared hosting environment iis(8) integrated mode.
observed that, if perform publish , map folder iis , request uri.
virtual folder maps published content returns 404 (local iis7.5)
virtual folder maps code folder returns data (local iis7.5)
set idenitiy of application pool localsystem , started work on local installation after publish.
Comments
Post a Comment