且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用ASP.NET MVC在查询字符串中使用身份验证令牌对用户进行身份验证

更新时间:2022-04-27 23:29:00

Uf,广泛的问题.但我至少会尝试将您引向正确的方向.

Uf, broad question. But I will try at least to direct you to a right direction.

因此,首先建议您使用表单身份验证"作为基础,但是您必须自定义使用它.而且我认为您不想使用cookie进行身份验证,因为这是表单身份验证的本机行为.

So first if suggest that you use Forms Authentication as a base, but you will have to customize using of it. And I presume that you do not want to use cookies for the authentication as this is native behaviour of the Forms Authentication.

您应该考虑使用自定义查询字符串令牌基于身份验证的方法.

The most important point you should consider to have it you custom query string token based authentication.

  1. 创建一个登录操作,如果用户已授予访问权限,则在该操作中您将授权该用户,您要求FormsAuthentication创建AuthCookie.要进一步了解,只需将httpCookie.Value用作您的身份验证令牌,您将在其中携带查询字符串.

  1. Create a login action and in this action you will authorize the user, if he have granted access you ask FormsAuthentication to create AuthCookie. For the further on you just take the httpCookie.Value as your auth token that you will carry in query string.

您需要在Global.asax中实现Application_BeginRequest,它将处理此查询字符串标记并将其转换为cookie .通过这种方法,您可以利用所有的ASP.NET Forms身份验证基础结构.

You need to implement the Application_BeginRequest in the Global.asax that will handle this query string tokens and translate it into the cookie. With this approach you can leverage all the ASP.NET Forms Authentication infrastructure.

这是没有代码的高级图片.如果您需要更多详细帮助,我也可以为您提供.

This is quite high level picture w/o code. If you need more detail help I can also provide it to you.