简体   繁体   English

如何通过Powershell设置IIS自定义错误?

[英]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: 我不得不:

  1. Enable IIS Powershell. 启用IIS Powershell。

     import-module WebAdministration 
  2. Remove language prefix 删除语言前缀

     Set-WebConfigurationProperty -PSPath IIS:\\Sites\\YOUR_SITE_NAME -Filter "/system.webServer/httpErrors/error[@statusCode='404']" -Name "prefixLanguageFilePath" -Value "" 
  3. 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 "/" 
  4. 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.

相关问题 如何通过Powershell脚本设置IIS 10.0管理服务SSL证书以允许Web部署? - How do I set the IIS 10.0 Management Service SSL Certificate via a Powershell script to allow Web Deploy? 如何通过PowerShell设置IIS网站(不是应用程序池)标识字段(用户名和密码)? - How can I set up IIS website (not Application Pool) identity fields (username & password) via PowerShell? 如何通过 PowerShell 在 IIS 中继限制上设置“除下面的所有列表” - How to set "All Except List Below" on IIS relay restriction via PowerShell 如何使用 Powershell 在 IIS 中设置“ConnectAs”用户 - How to set "ConnectAs" user in IIS using Powershell 如何访问IIS:通过Powershell在远程计算机上驱动? - How to access IIS: drive on remote machine via Powershell? 如何通过PowerShell远程更改IIS应用程序池设置? - How to remotely change IIS Application Pool setting via PowerShell? 通过 PowerShell 配置 IIS 8.5:如何删除继承文件夹授权 - Configuring IIS 8.5 via PowerShell: how remove inherit folder authorization 如何通过powershell删除非IIS、OS源头文件? - How to remove non-IIS , OS source headers via powershell? 如何通过 PowerShell 或图形 API 在 Micosoft Teams 中设置成员设置“允许成员上传自定义应用程序” - How to set membersetting “allow member to upload custom apps” in Micosoft Teams via PowerShell or Graph API 如何通过Powershell在Outlook中设置VotingRespons - How to Set VotingResponses in Outlook via Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM