MVC3:一个控制器是否需要 Windows 身份验证,而第二个控制器允许匿名?
我有一个控制器,用于在需要 Windows 身份验证的内部 Web 应用程序中呈现页面。是否存在第二个控制器,用于对系统进行基于 JSON 的查询,不需要进行 Windows 身份验证?这可能吗?看来我目前只能做其中之一。
有什么建议吗?
I have one controller that renders pages in an internal web application that needs to be windows authenticated. There exists a second controller used for JSON-based queries into the system that do NOT need to be Windows Authenticated? Is that possible? It appears I've only been able to do one or the other at the moment.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我们有一些应用程序需要执行此操作。通常,我们的应用程序被锁定在 web.config 中:
但是,您仍然必须关闭该 API 控制器的 Windows 身份验证。您可以通过编辑 IIS 服务器上的
applicationHost.config
文件并添加以下内容来完成此操作:此 PowerShell 脚本将为您完成此操作:
We have a few apps that need to do this exact thing. Often, our apps are locked down in the web.config:
However, you still have to turn off Windows authentication for that API Controller. You can do this by editing the
applicationHost.config
file on the IIS server and adding:This PowerShell script will do it for you:
是的。根据您选择的身份验证,您可以使用 授权
本文准确呈现了您正在寻找的内容:
http://www.asp.net/mvc/教程/authentiating-users-with-windows-authentication-cs
来自文章“例如,清单 1 中的 Home 控制器公开了三个名为Index()、CompanySecrets() 和 StephenSecrets()。任何人都可以调用 Index() 操作,但是,只有 Windows 本地 Managers 组的成员才能调用 CompanySecrets() 操作。在 Redmond 域中)可以调用 StephenSecrets() 操作。”
Yes. Based on what authentication you choose, you decorate your controller's action method with Authorize
This article presents exactly what you are looking for:
http://www.asp.net/mvc/tutorials/authenticating-users-with-windows-authentication-cs
From the article "For example, the Home controller in Listing 1 exposes three actions named Index(), CompanySecrets(), and StephenSecrets(). Anyone can invoke the Index() action. However, only members of the Windows local Managers group can invoke the CompanySecrets() action. Finally, only the Windows domain user named Stephen (in the Redmond domain) can invoke the StephenSecrets() action."
,您可以使用 AuthorizeAttribute 处理此问题
是的 例如,在一个简单的帐户控制器中,您只希望授权用户访问操作
ChangePassword
yes you can handle this with AuthorizeAttribute
So for example in a simple account controller you only want authorized users to access the Action
ChangePassword