ASP.NET MVC4和Web API认证+授权(Windows 8和网络) [英] ASP.NET MVC4 and Web API Authentication + Authorization (Windows 8 and Web)

查看:357
本文介绍了ASP.NET MVC4和Web API认证+授权(Windows 8和网络)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用简单会员数据库,用于存储用户,角色和配置文件创建一个ASP.NET MVC 4互联网Web应用程序。

I created an ASP.NET MVC 4 Internet Web Application using Simple Membership db for storing users, roles and profiles.

在我的应用我创建了一个Web API控制器将在响应HTTP:// 127.0.0.1/api/users 键,此调用将返回所有列表存储在数据库中的用户为 JSON

In my app I created a Web API controller that will respond to the http:// 127.0.0.1/api/users and this call will return a list of all users stored in the db as JSON.

UsersController 装饰有 [授权] 属性,因此任何呼叫 HTTP :// 127.0.0.1/api/users 必须进行身份验证

The UsersController is decorated with [Authorize] attribute therefore any call to the http:// 127.0.0.1/api/users have to be authenticated.

在主网页我有一个按钮,一旦pressed执行jQuery的AJAX GET请求,并会显示在Web API(JSON)返回的用户列表。

On the main page I have a button that once pressed a jQuery ajax get request is performed and will show the list of users returned by the Web API (json).

如果我登录,我preSS按钮,一切工作正常...用户列表检索和显示。

If I am logged in and I press the button, everything works fine ... the list of users is retrieved and shown.

如果我没有登录,消息显示的是 401 - 未授权(jQuery的呼叫状态code自定义消息),所以它的工作原理,因为它应该是因为在 [授权] 属性。

If I am not logged in, the message show is 401 - Unauthorized (custom message in jquery call statusCode) so it works as it should because of the [Authorize] attribute.

我的问题:我怎么能当一个Web API使得它的请求,让用户的列表,并从Windows 8的应用程序或Windows Phone 8或Windows窗体例如告诉他们鉴别?换句话说,从除了web浏览器等客户端

My question: How can I authenticate when a Web API makes a request to it, to get the list of users and show them from a Windows 8 app or Windows Phone 8 or Windows Forms for example? In other words, from a client other than the web browser?

推荐答案

您应该让另一个API,即检查从Windows 8的应用程序或Windows身份验证。

You should make another api, that checks the authentication from the Windows 8 app or Windows.

如果其从认证成功传,那么只有你必须显示用户列表到客户端。

If its pass successfully from the authentication, then only you have to show user list to the client.

这篇关于ASP.NET MVC4和Web API认证+授权(Windows 8和网络)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆