Angular JS和Web API 2外部身份验证

时间:2014-04-20 01:33:33

标签: cors facebook-authentication asp.net-web-api2

是否可以在外部认证中使用Web API 2构建,而Angular JS托管在不同的Web服务器上?如果是这样,有人知道一个例子吗?

我正努力让它发挥作用。 Facebook的请求给了我一个CORS问题。我不确定发生了什么。

我唯一的猜测是重定向来自与托管的web api不同的域。这是facebook配置的内容。

1 个答案:

答案 0 :(得分:0)

您可以使用免费的第三方DLL启用CORS,只需按照以下步骤操作即可 1.下载为你的项目添加" owin cors" dll的参考资料 2.在Web api中添加一个类文件

public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            ConfigureAuth(app);

            WebApiConfig.Register(config);

            app.UseWebApi(config);


        }
    }
3. Decorate your class  with 
[assembly: OwinStartup(typeof(YourNameSpaces.Startup))]