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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -