有时我需要阻止对网站的访问,但我不想阻止管理员访问,因此他们应该能够看到该网站,为此我想我需要制作一个模块。
如何制作这样的模块?
这是我的代码。我只是不知道我应该把它放在哪里。
var user = Membership.GetUser() as User;
if (user == null || (user != null && !user.IsAdministrator))
{
// Block
}
最佳答案
您可以使用 web.config 文件配置您的目录来阻止对站点或站点的一部分的访问。
举个例子,
<location path="/admin">
<system.web>
<authorization>
<deny users="*" />
<allow role="Administrator" />
</authorization>
</system.web>
</location>
编辑:根据您上面的评论,您可能对 bottom of this article 中描述的技术感兴趣。用于使应用程序脱机但仍允许管理访问。
参见 docs on the location element获取更多示例和信息。
关于c# - 如何创建一个模块以仅允许管理员访问该网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3578067/