- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的网站(带有 Entity Framework 的 ASP.NET MVC5)使用 Windows 身份验证系统。它非常有用,使我能够通过搜索 Active Directory 获得有关用户的更多信息。我可以使用电子邮件等信息自动填写表单字段,...
Web.config:
[...]
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
[...]
我有一个 Powershell 脚本(做另一项工作),它必须访问网站的一个页面才能发送一些信息。我需要提供对脚本的访问权限,无需任何身份验证(仅为此操作/页面关闭 Windows 身份验证)。我最初使用的是属性 AllowAnonymous,它没有效果。
我的 Controller 中的操作:
[AllowAnonymous]
public ActionResult ReceiveData(string scriptVersion, string content)
{
try
{
if (scriptVersion != null && content != null)
{
HttpUtility.UrlDecode(content);
Xxxxx.UpdatexxxxxxServer(content); // I just replaced the name of my project
return new HttpStatusCodeResult(200, "OK");
}
return new HttpStatusCodeResult(403, "You're not allowed to do this.");
}
catch(Exception e)
{
return new HttpStatusCodeResult(400, "Unable to execute this request on the DB. Detailed error: " + e.Message);
}
}
Powershell脚本(仅供引用,本题无需理解):
$url = "http://localhost:3349/Xxxxxx/ReceiveData"
$parameters = "scriptVersion=2&content=$([System.Web.HttpUtility]::UrlEncode($(Get-Content "$scriptFile")))"
$http_request = New-Object -ComObject Msxml2.XMLHTTP
$http_request.open('POST', $url, $false)
$http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
$http_request.setRequestHeader("Content-length", $parameters.length)
$http_request.setRequestHeader("Connection", "close")
$http_request.send($parameters)
当我的脚本到达发送方法时,他要求我提供凭据,而我不想每次都提供凭据(而且我不想将我的凭据放在脚本中)。这就是为什么我希望在此操作上禁用 Windows 身份验证。
我做了一些研究,试图找到任何可行的解决方案。我看到了这个主题:MVC 5.0 [AllowAnonymous] and the new IAuthenticationFilterAllowAnonymous 属性似乎在添加新过滤器的 MVC5 中不起作用。这就是我尝试添加自定义过滤器的原因:
public class CustomAuthenticationAttribute : ActionFilterAttribute, IAuthenticationFilter
{
public void OnAuthentication(AuthenticationContext filterContext)
{
}
public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext)
{
var user = filterContext.HttpContext.User;
if (user == null || !user.Identity.IsAuthenticated)
{
filterContext.Result = new HttpUnauthorizedResult();
}
}
}
我将它添加到 FilterConfig 上,并将 CustomAuthenticationAttribute 放在我的 Action ReceiveData 上。 没有更好的结果...所有操作都在此过滤器中进行,但我无法对我的操作禁用 Windows 身份验证。
我修改的 Action :
[AllowAnonymous]
[CustomAuthenticationAttribute]
public ActionResult ReceiveData(string scriptVersion, string content) {
[...]
}
我不是专家,如果您能帮助我找到解决方案并理解它,那就太好了。提前致谢,对于英语错误,我深表歉意,这不是我的母语。
最佳答案
我就是这样做的:
notepad
作为管理员%WINDIR%\System32\inetsrv\config\applicationHost.config
%WINDIR%\System32\inetsrv\config\applicationHost.config.bak
用于备份目的找到以下字符串:
<section name="anonymousAuthentication" overrideModeDefault="Deny" />
Deny
与 Allow
%WINDIR%\System32\inetsrv\config\applicationHost.config
web.config
<configuration>
节将此粘贴到您的 <configuration>
中部分:
<!-- ANONYMOUS ACCESS FOR POWERSHELL SCRIPT -->
<location path="ReceiveData.aspx">
<system.webServer>
<security>
<authentication>
<anonymousAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</location>
web.config
I have modifed the .config file. Is it only available for local IIS?
是的,此方法使用 IIS 配置匿名身份验证。我无法帮助编写代码,因为我不是开发人员。也许您应该等待具有实际 C# 知识的人来回答。
Do I must to perform this change on my "non-development" environment?
是的,您必须在 %WINDIR%\System32\inetsrv\config\applicationHost.config
中更改全局设置能够覆盖 anonymousAuthentication
在每个应用程序中 web.config
.
About the code: I work with MVC, so i don't have any .aspx pages. I changed the path to MyController/ReceiveDate, is it correct?
可能吧。 <location path=>
必须是“相对虚拟路径”,即 "root relative virtual path to the script or path for the current request"
I don't have "recycle the app pool" because I really don't know how to do this : I work with the IIS Visual Studio.
不需要回收应用程序池,如果 IIS 检测到 web.config
,IIS 应该自行回收它变化。但它很少不发生或发生时有明显的延迟。
After testing my PowerShell script with your solution, I get an error 500.19.
什么是 HRESULT
错误代码?也许您在 web.config
中输入了错误的内容?详情请看这篇文章:"HTTP Error 500.19" error when you open an IIS 7.0 Webpage
关于c# - ASP.NET MVC5 : Turn off Windows Authentication on a single page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33345989/
我一直在探索 Mapbox Map SDK 和 Navigation SDK,但遇到了瓶颈,如有任何帮助,我们将不胜感激。 我在 GeoJSON 中定义了一些路由。是否可以将 GeoJSON 中的这条
我在 C 中有两个静态可变变量,我想在逻辑语句中检查它们。但是,当我这样做时,我收到警告“未定义的行为:此语句 1037 中未定义 volatile 访问的顺序”是否有可能在很短的时间内暂停 C 变量
有没有像 googlemaps 应用程序和 mapkit 那样做 turn-by-turn mapping 的方法?就像下面的图片。谢谢 最佳答案 我猜你想在你的应用程序中使用精细导航?在 MapKi
我正在构建一个 Android 应用程序,帮助用户在两点之间导航。这是 doc 的链接.这正是我想要提供给用户的功能,但是我希望导航在我的应用程序中进行,而不是通过以这种方式启动 Intent Uri
我正在开发从当前位置到目的地的转弯导航。我使用以下代码完成了此操作 Uri gmmIntentUri = Uri.parse("google.navigation:q="+address); Inte
假设我有一个控制 android 服务的开关:当Switch处于“on”状态时,表示服务正在运行,当开关处于“关闭”位置时,表示服务未运行。此外,当用户点击 Switch 时,它应该切换服务(因此切换
我正在尝试实现一种算法来填充一个区域,该特定算法在以下 Wikipedia 中给出“固定内存法(右手填充法)”标题下的文档。下面给出算法中发生左转和右转的特定部分... START: set
我正在使用 HERE NOKIA SDK。我已经在 2 点和语音指令之间创建了一条路线。现在我想显示图像箭头和操作的特定文本。 最佳答案 SDK不提供回合图标。请创建一些图像以将它们与机动转弯类型配对
我的应用程序需要像 OLA、UBER 和出租车出租应用程序一样包含转弯 GPS 导航。我使用 Google Direction API 来显示路径和持续时间。我检查了以下链接,但对我没有帮助。 gps
我的应用需要包含转弯 gps 导航。任何人都可以告诉如何通过转弯 gps 导航集成谷歌地图。 我可以在android开发中找到它。但是我无法从谷歌地图的 iOS 开发文档中找到导航。 https://
构建时出现以下错误: ...has undefined behavior [-Werror,-Wundefined-reinterpret-cast] Bazel 构建完全停止,因为 clang (l
如何关闭 Rmd HTML 文档中的标题? --- title: "" output: html_document --- rmarkdown::render("index.Rmd") [WARNIN
我试图使用 部署一个简单的 TURN 服务器coturn . 当我在 Trickle ICE 上测试时( turn:rtc.jackxujh.me:3478 [webrtc:mighty] ),Tri
我正在使用一个任性的库,不幸的是,它会将信息打印到 System.out(或偶尔打印到 System.err)。防止这种情况的最简单方法是什么? 我一直在考虑创建一个输出流到内存,在每次调用其中一个麻
比如说我搭建了WebRTC视频聊天网站,有的握手后连接(ICE Candidates)会直接p2p,有的会使用STUN服务器,有的会使用“不得已”的TURN服务器建立连接.与直接连接和 STUN 连接
我在查找有关如何“打开”mysqli 的确切文档时遇到了麻烦。我正在运行 OS X SL,据我所知,由于安装了 php5,mysqli 扩展也应该已经存在。 这是否像在 php.ini 中添加 Loa
在我的 Ubuntu 引擎上设计了一个简单的基于 shell/bash 的备份脚本并使其工作后,我将它上传到了我的 Debian 服务器,它在执行它时会输出一些错误。 我该怎么做才能在我的 Ubunt
我正在使用 Twilio Network Traversal Service作为 native 应用程序的一部分,我是 working on执行对等远程桌面连接。我们实现了 WebRTC 协议(pro
我正在尝试将负载均衡器放在 Turn 服务器前面以与 WebRTC 一起使用。我在下面的示例中使用了一个轮流服务器,直到负载平衡器正常工作。 Turn 服务器需要多个端口,包括一个 UDP,如下所示:
在哪些情况下我应该使用 TURN 服务器? 现在我有一个完美运行的 WebRTC 应用程序。该应用程序即将发布。 我是否需要设置自己的 TURN 服务器,或者这可能仅适用于主要应用程序? 最佳答案 已
我是一名优秀的程序员,十分优秀!