【发布时间】:2018-06-23 11:27:26
【问题描述】:
到目前为止我做了什么:
-
使用此 web.config 创建网站(这只是设置部分,而不是整个文件 :))
<appSettings> <add key="webpages:Version" value="3.0.0.0"/> <add key="webpages:Enabled" value="false"/> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled" value="true"/> <add key="autoFormsAuthentication" value="false"/> <add key="enableSimpleMembership" value="false"/> </appSettings> <system.web> <compilation debug="true" targetFramework="4.6.2"/> <httpRuntime targetFramework="4.6.2"/> <authentication mode="Windows"></authentication> <authorization> <deny users="?"/> </authorization> </system.web> -
创建了一个控制器:
[Authorize(Users = @"myPcName\myUserName,skynet\Simple")] public class AuthenController : Controller { [Authorize(Users = @"myPcName\myUserName")] public ActionResult ForAdministrator() { return View(); } [Authorize(Users = @"myPcName\Simple")] public ActionResult ForUser() { return View(); } }
我通过 cmd -> whoami 获得了我的凭据
它只是一次又一次地提示我输入凭据:
【问题讨论】:
-
因为您在安全设置中将用户身份验证指定为提示输入用户名和密码!
-
如果你只使用
[Authorize],它是否有效?可能是您不需要指定 PC 名称并且它不起作用,因为它无法识别用户名 -
嗨@Kaj,即使我将互联网选项设置为“匿名登录”,它仍然无法正常工作
-
@TAHASULTANTEMURI,不是。我尝试了那里的建议,但没有奏效。
标签: c# asp.net-mvc authentication windows-authentication