c# - 不断提示输入凭据
问题描述
到目前为止我做了什么:
使用此 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
- 我以发布模式将我的 mvc 站点发布到 c:\inetpub\wwwroot\backoffice
它只是一次又一次地提示我输入凭据:
解决方案
只是为了帮助遇到这个问题的任何人:我解决问题的方法是:单击 VS 中的项目。按 F4 转到属性 将“匿名身份验证”设置为禁用
在 web.config 中:
<authentication mode="Windows"></authentication>
<authorization>
<allow users="*" />
</authorization>
在你的控制器中:
[Authorize(Users = @"pcName\user")]
public ActionResult ForAdministrator()
{
return View();
}
// Authorization with windows authentication (user)
[Authorize(Users = @"pcName\user")]
public ActionResult ForUser()
{
return View();
}
其中 pcName 是您的电脑的名称(不是 WORKGROUP!)
通过这种方式,您可以控制谁被允许(因为匿名身份验证被禁用)。
希望它可以帮助某人。罗腾
推荐阅读
- reactjs - 无法使用 Material-UI 进行编译:找不到模块:无法解析 '@babel/runtime/core-js/object/get-prototype-of'
- ghostscript - Ghostscript 从 PDF 生成大型 PostScript 文件
- javascript - 用值数组替换正则表达式匹配
- git - 如何使用 precommitter 钩子在父项目中提交来自子模块的更改
- python - 芹菜分配队列和工人
- jquery - fn.load 已弃用
- selenium - 如何编写一个 CSS 选择器来选择没有特定属性的元素?
- javascript - 使用参数字典调用类的构造函数
- java - 片段添加事务后仍然出现来自 Activity 的小部件布局
- java - 错误 CoarseGrainedExecutorBackend: RECEIVED SIGNAL TERM