网页API认证和MVC 4 [英] Web api authentication and MVC 4

查看:118
本文介绍了网页API认证和MVC 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下解决方案:


  1. 的Web API项目。

  2. MVC 4项目。

我需要使用JSON请求(HTTPS是必须的)发送其凭据进行身份验证的用户。
 这是一个好的方法?我怎么能验证两个网页API和MVC。

用户
解决方案

  

这是一个好的方法呢?


是啊,为什么不呢?


  

和我如何可以验证两个网页API和MVC。

用户

如果在Web API需要身份验证,你可以使用相同的窗体身份验证的MVC应用程序。所以,你可以在Web API应用程序的web.config配置表单身份验证,然后装饰需要使用验证[授权] 属性的操作。然后,需要查询这些方法的客户将需要包括窗体身份验证Cookie在请求中。

要注意的是,为了使网络的API能够解密被发射的MVC应用形式验证cookie是很重要的,这两个应用程序需要共享同一 计算机密钥

I have the following solution:

  1. Web api project.
  2. MVC 4 project.

I need to authenticate user by sending its credentials using a JSON request (https is a must). is it a good approach ? and how can i authenticate the user on both web api and MVC .

解决方案

is it a good approach ?

Yeah, why not.

and how can i authenticate the user on both web api and MVC .

If the Web API requires authentication you could use the same Forms Authentication as the MVC application. So you could configure Forms Authentication in the web.config of the Web API application and then decorate the actions that require authentication with the [Authorize] attribute. Then clients that need to query those methods will need to include the Forms Authentication cookie along with the request.

It is important to note that in order for the Web API to be able to decrypt the forms authentication cookie that was emitted the MVC application, both applications need to share the same machine keys.

这篇关于网页API认证和MVC 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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