在生产中隐藏 MVC 页面
我有一个新的 MVC 应用程序,它集成到一个更大的现有 Intranet 站点中。
在生产中,身份验证详细信息将从现有的 Intranet 站点传递。但在开发中我需要一个本地表单登录控件来创建身份验证。
这意味着当解决方案部署到生产服务器时,我需要一种方法来隐藏任何本地登录页面。我试图使用 Debugger.IsAttached 来重定向离开任何登录页面,
public class AccountController : Controller
{
public ActionResult LogOn()
{
if (!System.Diagnostics.Debugger.IsAttached)
RedirectToAction("NotFound");
return View();
}
}
但事实证明这不起作用。由于某种对我来说是个谜的原因,导航到 /Account/LogOn
时仍然可以提供登录页面。
我可以解决这个问题吗?有更好的办法吗?
I have a new MVC application which integrates into a larger pre-existing intranet site.
In production, authentication details will be passed from the existing intranet site. But in development I need a local forms login control to create the authentication.
This means I need a way to hide any of the local login pages when the solution is deployed to production server. I was trying to use Debugger.IsAttached
to redirect away from any login page
public class AccountController : Controller
{
public ActionResult LogOn()
{
if (!System.Diagnostics.Debugger.IsAttached)
RedirectToAction("NotFound");
return View();
}
}
It turns out this doesn't work. For some reason which is a mystery to me, the login page is still served when navigating to /Account/LogOn
.
Can I fix this? Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有用于生产和开发的单独的 Web.config,则可以在生产环境的 Web.config 中限制对此操作的访问:
If you have a separate Web.config for both production and development, you can restrict access to this action in the Web.config of the production-environment:
只是出于好奇,您知道“授权”属性吗?
http://msdn.microsoft.com/en-us /library/system.web.mvc.authorizeattribute.aspx
您提到您的应用程序是一个更大的应用程序的一部分,我认为该应用程序处理安全性(身份验证),对吧?
如果是这样,在开发过程中,您可以有一个不同的/特定的 web.config 来满足您的需求。
另外,
我建议您使用编译器的指令,而不是 Debugger.IsAttached
Just out of curiousity, are you aware of the "Authorize" attribute?
http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx
You mention that your application is part of a larger application that I assume deals with the security (authentication), right ?
If so, in development, you could have a different/specific web.config for your needs.
Also,
Instead of the Debugger.IsAttached, I suggest you use the compiler's directive