为网站的私人测试版添加安全层的最不显眼的方法是什么?

发布于 2024-07-29 02:48:23 字数 685 浏览 4 评论 0原文

假设我有一个 ASP.NET 站点(在本例中为 MVC),它使用表单身份验证和典型的会员系统。 该网站允许经过身份验证的用户和匿名用户。

当我将网站作为私人测试版发布时,我想在应用程序之上添加另一层安全性,例如超级用户的简单密码系统, 例如。 一旦用户通过了这一安全层,我仍然希望我的表单身份验证/会员系统到位,以便 Beta 测试人员可以以经过身份验证的或匿名用户的身份查看该网站。

实现这一目标的最不引人注目的方法是什么? 我正在寻找最简单的解决方案,需要最少的新代码或修改代码。 例如,我不想修改每个控制器来检查特殊的 cookie。 一定有更好的方法...

有一个非常相似 在这里提问,但似乎有问题的网站(一旦公开)只会服务匿名请求,所以它不一定与我的情况相比。 这个答案表明ServerFault使用了一些cookie系统,但没有关于如何实施的更多细节。

Let's say I have an ASP.NET site (MVC in this case) that uses Forms authentication and a typical membership system. The site allows both authenticated and anonymous users.

When I release the site as a private beta I want to add another layer of security on top of the application, like superuser's simple password system, for example. Once a user has passed this layer of security, I still want my forms authentication/membership system in place so beta testers can view the site as authenticated or anonymous users.

What's the most unobtrusive way to achieve this? I'm looking for the easiest solution that will require the least amount of new or modified code. E.g. I don't want to modify every controller to check for a special cookie. There must be a better way...

There's a very similar question here, but it seems the site in question (once public) will only serve anonymous requests, so it doesn't necessarily compare to my situation. This answer suggests ServerFault used some cookie system, but there are no further details about how it might have been implemented.

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

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

发布评论

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

评论(2

獨角戲 2024-08-05 02:48:23

在 IIS 中实现服务器级别的安全性,并在运行 IIS 服务器的 Windows 的 Active Directory 中添加帐户/密码。

您无需更改任何代码。

Implement security at server level, in IIS and add the accounts/passwords in Active Directory of Windows running the IIS server.

You won't need to change any of the code.

独﹏钓一江月 2024-08-05 02:48:23

好吧,我知道您不想修改当前的控制器,但这就是我对类似行为所做的操作。
我创建了一个自定义 ActionFilterAttribute,并将其提供给需要进行特定访问检查的每个控制器。 你可以有这样的东西:

public class CheckBetaAccess : ActionFilterAttribute {
   public override void OnActionExecuting(ActionExecutingContext filterContext) {
        if (!canAccess) {
            filterContext.Controller.ViewData["someViewData"] = "some text";
            filterContext.Result = new ViewResult {
                ViewName = "the-view-anonymous-users-should-see",
                ViewData = filterContext.Controller.ViewData
            };
            filterContext.Result.ExecuteResult(filterContext);
        }
    }
}

然后我装饰了我的控制器:

[CheckBetaAccess]
public class SomeController : Controller {
    //....
}

Well, I know you don't want to modify your current controllers but here's what I did for a similar behaviour.
I've created a custom ActionFilterAttribute that I've given to every controller that requires to have that specific access check. You can have something like this :

public class CheckBetaAccess : ActionFilterAttribute {
   public override void OnActionExecuting(ActionExecutingContext filterContext) {
        if (!canAccess) {
            filterContext.Controller.ViewData["someViewData"] = "some text";
            filterContext.Result = new ViewResult {
                ViewName = "the-view-anonymous-users-should-see",
                ViewData = filterContext.Controller.ViewData
            };
            filterContext.Result.ExecuteResult(filterContext);
        }
    }
}

Then I decorated my controllers :

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