c# - Web API CORS FormsAuthentication from AngularJS Client -
i implemented angularjs project. server side coded using .net web api (c#). enabled cors in web api installing nuget package https://www.nuget.org/packages/microsoft.aspnet.webapi.cors
[enablecors(origins: "*", headers: "*", methods: "*")] public class samplecontroller : apicontroller { [allowanonymous] [httpget] public string getanonymousstring() { formsauthentication.setauthcookie("sample allowanonymous", false); return "calling allowanonymous method using cors - public text"; } [authorize] [httpget] public string getauthorizestring() { return "calling authorize method using cors - private text"; } }
i hosted client side application in http://localhost:8050 , hosted service web api in http://localhost:8060.
now tried access getanonymousstring() - http://localhost:8060/api/sample/getanonymousstring working fine , returns httponly cookie client via response.
but tried same getauthorizestring() - http://localhost:8060/api/sample/getauthorizestring, returns 401 unauthorized error response.
if hosted client app , web api in same domain, working fine. issue cors.
kindly assist me how use authorize
in cors
???
Comments
Post a Comment