[英]How to set the IIS Custom Error via Powershell?
I'm trying to figure out how to set the IIS Custom Error for the error 401 using Powershell so I've tried this without success. 我试图弄清楚如何使用Powershell为错误401设置IIS自定义错误,所以我试过这个没有成功。
Set-WebConfigurationProperty -Filter "/system.webServer/httpErrors/error[@statusCode='401']" -Location IIS:\Sites\MySite -Name path -Value "~/Content/CustomErrors/401.html"
I want to achieve this configuration result. 我想实现这个配置结果。
Thanks in advance. 提前致谢。
after a long try-error loop, I finally figured out how to solve this, if anyone is interested I'm going to show you my resolution. 经过长时间的尝试错误循环后,我终于想出了如何解决这个问题,如果有人有兴趣,我会告诉你我的决议。
Set-Location IIS:\Sites\MySite
add-WebConfiguration -Filter /System.WebServer/HttpErrors -Value @{StatusCode=401;PrefixLanguageFilePath="$Null"; Path="~/Content/ErrorMessages/401.html"; ResponseMode="ExecuteURL"}
This worked for me, in my case I wanted to redirect to the index.html page in the root, for the 404 status error code 这对我有用,在我的情况下,我想重定向到根目录中的index.html页面,以获取404状态错误代码
I had to: 我不得不:
Enable IIS Powershell. 启用IIS Powershell。
import-module WebAdministration
Remove language prefix 删除语言前缀
Set-WebConfigurationProperty -PSPath IIS:\\Sites\\YOUR_SITE_NAME -Filter "/system.webServer/httpErrors/error[@statusCode='404']" -Name "prefixLanguageFilePath" -Value ""
Set the path value to the page I wanted to display on 404 http statuscode (In my case the root of the site) 将路径值设置为我想在404 http状态代码上显示的页面(在我的情况下是站点的根目录)
Set-WebConfigurationProperty -PSPath IIS:\\Sites\\YOUR_SITE_NAME -Filter "/system.webServer/httpErrors/error[@statusCode='404']" -Name "path" -Value "/"
Change response mode (type) to Execute URL 将响应模式(类型)更改为执行URL
Set-WebConfigurationProperty -PSPath IIS:\\Sites\\YOUR_SITE_NAME -Filter "/system.webServer/httpErrors/error[@statusCode='404']" -Name "ResponseMode" -Value "ExecuteURL"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.