usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSystem.Web.Http.Filters;namespacekingt.web.his.sys{ Public class supportcrossdomainattribute : System.Web.Http.Filters.ActionFilterAttribute { Public Override voidonactionexecuted (Httpactionexecutedcontext actionexecutedcontext) {varResheaders =actionExecutedContext.Response.Headers; if(allowcredentials) {Resheaders.add ("access-control-allow-credentials","true"); } resheaders.add ("Access-control-allow-origin", Origin??"*"); Base. OnActionExecuted (ActionExecutedContext); } Public BOOLallowcredentials {Get;Set; } Public stringOrigin {Get;Set; } }}
Add the above class namespace to your project to modify it according to your own. Then add the [supportcrossdomainattribute] attribute on each interface that requires a cross-domain call
[ Supportcrossdomainattribute] [HttpGet] [Route ("Status")] PublicIhttpactionresult Status () {varobj =New Object[] { New{id="-1", text="All" }, New{id="1", text="in use" }, New{id="0", text="Deactivate" } }; returnOk (obj); }
ASP. NET Web Api addresses cross-domain issues