ASP.NET MVC2 应用程序中的第二层身份验证

发布于 2024-09-16 02:39:20 字数 334 浏览 2 评论 0原文

我们有一个 ASP.NET 应用程序,部分采用 MVC(其余部分是基于 Web 表单的传统 CMS)。该应用程序通过表单身份验证进行身份验证,但从一组特定 IP 地址访问该应用程序的任何用户都会自动分配给“特殊”用户。

目前,我们有一个子应用程序,我们希望将其作为一个区域引入(父)MVC 应用程序。此应用程序使用 Windows 身份验证作为第二层身份验证。是否有一种简单的方法来保留第二层身份验证(可能通过第二授权属性)?请记住,用户可以从内部和外部登录此应用程序。在用于特殊表单身份验证用户的 IP 地址集之外,这排除了直接表单身份验证。如果这可以提供更简单的解决方案,那么我们也不必将第二层的 Windows 身份验证绑定在一起。

We have an ASP.NET application that's partly in MVC (the rest of it being a legacy webforms-based CMS). The application is authenticated via Forms Authentication, although any user accessing it from a specific set of IP addresses are automatically assigned to a "special" user.

We currently have a child application that we would ideally like to bring into the (parent) MVC application as an area. This application uses Windows Authentication as a 2nd layer of authentication. Is there an easy way of retaining the second layer of authentication (possibly by a 2nd authorize attribute)? This is bearing in mind the users can log into this application from both within & outside of the set of IP addresses used for the special forms authentication user, which rules out straight forms authentication. We're also not necessarily tied to windows authentication for this second layer if this makes for an easier solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迟到的我 2024-09-23 02:39:28

我还没有完全尝试过,但从我所看到的和我所看到的来看,到目前为止,我对自己的问题的解决方案是:

  1. 对受保护区域使用表单身份验证而不是 Windows 身份验证。
  2. 为允许访问此区域的某些用户创建角色相应地分配它。
  3. 创建一个新的自定义授权属性,将未经身份验证的用户发送到登录页面。在这种情况下,我需要这样做,因为应用程序将登录页面定义为 IP 检查器(而不是正确的登录页面),因此使用正常的授权属性将导致请求无限循环。该过程类似于此处,但我使用的是普通的 RedirectResult 而不是 RedirectToRouteResult,因为登录页面仍然在 WebForms 中而不是 MVC 中。
  4. (可选)由于我使用的是 MVC 区域,我什至可以 创建一个具有自定义授权属性的基本控制器从它派生所有其他控制器。这使我不必在每个控制器中为每个方法添加前缀(毫无疑问,可以防止我忘记在某个地方这样做!)。

不过,我仍然对其他解决方案持开放态度!

I'm yet to try it out fully, but from what I've seen & tried out thus far, my solution to my own problem is to:

  1. Use Forms authentication for the protected area instead of Windows authentication.
  2. Create a role for certain users who are allowed to access this area & allocate it accordingly.
  3. Create a new custom authorisation attribute, sending an unauthenticated users to the login page. In this case I need to do this as the application defines the login page to be the IP checker (instead of a proper login page), so using a normal authorisation attribute would cause a request infinite loop. The process is similar to the solution described here, except I'm using a plain RedirectResult instead of RedirectToRouteResult as the login page is still in WebForms instead of MVC.
  4. (Optional) since I'm using MVC Areas, I can even create a base controller with the custom authorisation attribute & derive all other controllers from it. This saves me from prefixing every method in every controller (& no doubt stop me from forgetting to do so somewhere!).

I am still open to other solutions though!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文