如何在没有数据库的情况下使用ASP.NET Identity

编程入门 行业动态 更新时间:2024-10-09 07:21:45
本文介绍了如何在没有数据库的情况下使用ASP.NET Identity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在MVC 5项目中使用新的ASP.NET身份实现自定义身份验证.

I am trying to implement custom authentication using the new ASP.NET Identity in an MVC 5 project.

我有一个单个用户名和密码,我想用来限制用户可以通过控制器和视图上的[Authorize]标签看到用户的网站页面. (容易)

I have a single username and password that I want to use to restrict which pages of the website the user can see via [Authorize] tags on controllers and views. (Easy)

我正在从FormsAuthentication模型进行迁移,该模型就像将凭据放入web.config一样简单.

I am migrating from a FormsAuthentication model whereby this was as simple as putting the credentials in the web.config.

因为我只有一个用户名和密码,我不想将数据库用作UserStore ,相反,我希望ASP.NET Identity可以从一个用户名和密码中检索用户名和密码. web.config中的自定义配置"部分(不必担心该部分).

Because I only have a single username and password I don't want to use a database as the UserStore, instead I want ASP.NET Identity to retrieve the username and password from a custom configurationsection in the web.config (don't worry about that part).

经过大量搜索,我找不到不依赖数据库进行ASP.NET身份验证的代码示例.

After much search, I can't find a code sample that doesn't rely on a database for ASP.NET Identity authentication.

因此,我正在寻找一个代码示例,以便在身份验证时,用户可以输入自定义代码来检查用户名&密码与web.config的自定义ConfigurationSection中的凭据相对应.

So i'm looking for a code sample that at the point of authentication, the user can put in custom code to check the username & password against the credentials in the custom ConfigurationSection of the web.config.

有人可以向我指出正确的方向吗?

Can someone please point me in the right direction thanks.

更新:我尝试查看此代码示例,但它甚至没有开箱即用地编译. code.msdn.microsoft/Simple-Aspnet-Identiy -Core-7475a961

Update : I've tried looking at this code sample but it doesn't even compile out of the box.. poor. code.msdn.microsoft/Simple-Aspnet-Identiy-Core-7475a961

更新:我不想使用FormsAuthentication的原因是我正在编写将要安装到Web应用程序中的NuGet程序包. NuGet软件包将要做的一件事是在web.config中创建一个自定义ConfigurationSection,其中包括(其中包括)单个用户名和密码.我认为这样做会更安全,因为它不会更改目标Web应用程序中当前存在的任何现有FormsAuthentication设置.

Update : The reason that I don't want to use FormsAuthentication is that I am writing a NuGet package that will be installed into a web application. One of the things the NuGet package will do is create a custom ConfigurationSection in the web.config that includes (among other things) a single username and password. I thought this would be safer as it wouldn't alter any existing FormsAuthentication settings currently in the target web application.

更新:我认为我已经开始使用它了.即将发布调查结果.

Update : I think I have got it working. Will post findings soon.

-李

推荐答案

我现在在这里有代码的工作副本 github/leeenglestone/ASP.NET-Identity-Without-a-Database

I now have a working copy of the code here github/leeenglestone/ASP.NET-Identity-Without-a-Database

它很大程度上基于Santosh Poojari已经完成的工作

It is based heavily on the work already done by Santosh Poojari

-李

更多推荐

如何在没有数据库的情况下使用ASP.NET Identity

本文发布于:2023-11-07 15:42:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:情况下   数据库   如何在   Identity   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!