Question: Can someone tell me how to "approve server variable REMOTE_ADDR" in IIS 8?
问题:有人能告诉我如何在IIS 8中“批准服务器变量REMOTE_ADDR”吗?
Background:
I have IIS 8 on a Windows 2012 server, but I do all my website development from my PC, which is not on that server. My asp.net is version 4.5. In Visual Studio, the solution is a "website" and I publish my files by using "Build > Publish Website."
我在Windows 2012服务器上安装了IIS 8,但是我从我的PC上进行了所有网站开发,而不是在那台服务器上。我的asp.net是4.5版。在Visual Studio中,解决方案是一个“网站”,我使用“Build> Publish Website”发布我的文件。
To handle custom errors I have this block in my Web.config file. The problem is that I get the same error pages everyone else does when I'm working on pages in Visual Studio viewing them from the localhost on my PC. When I do that, I manually comment out this block and enable another where the custom errors mode is off, and then switch it back when I do another website refresh to the server. (This happens a lot when a website is still in a development phase.)
为了处理自定义错误,我在Web.config文件中有这个块。问题是当我在Visual Studio中的页面上工作时,我得到了与其他人一样的错误页面。当我这样做时,我手动注释掉这个块并启用自定义错误模式关闭的另一个块,然后当我再次向服务器刷新网站时将其切换回来。 (当网站仍处于开发阶段时,这种情况会发生很多。)
I changed the mode to "RemoteOnly." This highlights another problem with having to change the mode back and forth: you sometimes forget to switch it back. Case in point.
我将模式更改为“RemoteOnly”。这突出了必须来回更改模式的另一个问题:您有时会忘记将其切换回来。一个很好的例子。
<customErrors mode="RemoteOnly" defaultRedirect="~/Error_Pages/Error.aspx">
<error statusCode="400" redirect="~/Error_Pages/4xx.aspx" />
<error statusCode="401" redirect="~/Error_Pages/Unauthorized.aspx" />
<error statusCode="403" redirect="~/Error_Pages/4xx.aspx" />
<error statusCode="404" redirect="~/Error_Pages/4xx.aspx" />
<error statusCode="410" redirect="~/Error_Pages/4xx.aspx" />
</customErrors>
I was hoping there might be a better solution, such as a way to tell IIS that I need to have custom errors off automatically. I came across this page via another * post, but the article appears to be written for an earlier version of Windows Server and/or IIS.
我希望可能有更好的解决方案,例如告诉IIS我需要自动关闭自定义错误的方法。我通过另一个*帖子看到了此页面,但该文章似乎是为早期版本的Windows Server和/或IIS编写的。
According to the article, there are only three simple steps for solving my problem. I already have step 1 done. I was unable to complete step 2 because I could not find any way to do that in IIS version 8.
根据这篇文章,解决我的问题只有三个简单的步骤。我已经完成了第1步。我无法完成第2步,因为我在IIS版本8中找不到任何方法。
- Set RemoteOnly for customErrors
- Have server administrator approve server variable REMOTE_ADDR
- Create URL Rewrite rule
为customErrors设置RemoteOnly
让服务器管理员批准服务器变量REMOTE_ADDR
创建URL重写规则
I did a Google search for clarification on #2, but it only led me back to the same article I posted.
我在谷歌搜索了#2的澄清,但它只是让我回到了我发布的同一篇文章。
To provide further clarification, on opening IIS on the server and following the instructions, I do not see "URL Rewrite section" as an icon. The same reason I was not able to apply step #2 in the article that I cited was because I did not see the necessary link or icon in IIS.
为了进一步说明,在服务器上打开IIS并按照说明操作时,我没有看到“URL Rewrite section”作为图标。同样的原因我无法在我引用的文章中应用第2步,因为我没有在IIS中看到必要的链接或图标。
This is a screenshot of what I see in my IIS version 8.
这是我在IIS版本8中看到的截图。
2 个解决方案
#1
If the url rewrite option is not installed on your server, download and install the extension.
如果服务器上未安装url rewrite选项,请下载并安装扩展。
Read the referenced post carefully to execute step 2:
仔细阅读引用的帖子以执行第2步:
- Open the site in the IIS Manager
- Double-click on/open the "URL Rewrite section":
- Click "View Server Variables":
- Right-click the panel to open the context menu or use the action menu on the right to Add the variable:
在IIS管理器中打开该站点
双击/打开“URL Rewrite section”:
单击“查看服务器变量”:
右键单击面板以打开上下文菜单,或使用右侧的操作菜单添加变量:
Note:
As others are mentioning, there are more advanced solutions to debugging your application. The ones that come to mind are:
正如其他人所说,有更多高级解决方案来调试您的应用程序。想到的是:
- Application Insights / New Relic
- More advanced logging in your code so you can monitor the Windows Eventlog
- Elmah
- Intellitrace will allow you to collect a log of the actions on the server and debug locally.
应用见解/新遗物
更高级的代码记录,以便您可以监视Windows事件日志
Intellitrace将允许您收集服务器上的操作日志并在本地进行调试。
To easily manage differences between development and production config files, make use of a Configuration Transformation. There are several tools that make that easier like SlowCheetah.
要轻松管理开发和生产配置文件之间的差异,请使用配置转换。有几种工具可以让它像SlowCheetah一样容易。
#2
You should test and fix your application locally before publishing, or create a fake (secured) website in your server and do some debugging. However, I recommend you to install ELMAH to log your errors and view them nicely in a secure page of your website. You can use Nuget, search for Elmah or Elmah.mvc package (if you use asp.net mvc ;) and install it... you can connect it to your SQL Server database, save the logs in memory and other formats. I wouldn't waste time configuring IIS or asking permission to administrators.
您应该在发布之前在本地测试和修复您的应用程序,或者在您的服务器中创建一个虚假(安全)的网站并进行一些调试。但是,我建议您安装ELMAH以记录您的错误,并在您网站的安全页面中很好地查看它们。您可以使用Nuget,搜索Elmah或Elmah.mvc包(如果您使用asp.net mvc;)并安装它...您可以将它连接到您的SQL Server数据库,将日志保存在内存和其他格式。我不会浪费时间配置IIS或向管理员请求权限。
Also you can use web.config transformations to automate the publish process. There is a "web.Release.config" file that is used by IIS when you publish your app (or in Release mode). Here is a good article from the asp.net official site.
您还可以使用web.config转换来自动执行发布过程。在发布应用程序时(或在发布模式下),IIS会使用“web.Release.config”文件。这是asp.net官方网站上的一篇好文章。
#1
If the url rewrite option is not installed on your server, download and install the extension.
如果服务器上未安装url rewrite选项,请下载并安装扩展。
Read the referenced post carefully to execute step 2:
仔细阅读引用的帖子以执行第2步:
- Open the site in the IIS Manager
- Double-click on/open the "URL Rewrite section":
- Click "View Server Variables":
- Right-click the panel to open the context menu or use the action menu on the right to Add the variable:
在IIS管理器中打开该站点
双击/打开“URL Rewrite section”:
单击“查看服务器变量”:
右键单击面板以打开上下文菜单,或使用右侧的操作菜单添加变量:
Note:
As others are mentioning, there are more advanced solutions to debugging your application. The ones that come to mind are:
正如其他人所说,有更多高级解决方案来调试您的应用程序。想到的是:
- Application Insights / New Relic
- More advanced logging in your code so you can monitor the Windows Eventlog
- Elmah
- Intellitrace will allow you to collect a log of the actions on the server and debug locally.
应用见解/新遗物
更高级的代码记录,以便您可以监视Windows事件日志
Intellitrace将允许您收集服务器上的操作日志并在本地进行调试。
To easily manage differences between development and production config files, make use of a Configuration Transformation. There are several tools that make that easier like SlowCheetah.
要轻松管理开发和生产配置文件之间的差异,请使用配置转换。有几种工具可以让它像SlowCheetah一样容易。
#2
You should test and fix your application locally before publishing, or create a fake (secured) website in your server and do some debugging. However, I recommend you to install ELMAH to log your errors and view them nicely in a secure page of your website. You can use Nuget, search for Elmah or Elmah.mvc package (if you use asp.net mvc ;) and install it... you can connect it to your SQL Server database, save the logs in memory and other formats. I wouldn't waste time configuring IIS or asking permission to administrators.
您应该在发布之前在本地测试和修复您的应用程序,或者在您的服务器中创建一个虚假(安全)的网站并进行一些调试。但是,我建议您安装ELMAH以记录您的错误,并在您网站的安全页面中很好地查看它们。您可以使用Nuget,搜索Elmah或Elmah.mvc包(如果您使用asp.net mvc;)并安装它...您可以将它连接到您的SQL Server数据库,将日志保存在内存和其他格式。我不会浪费时间配置IIS或向管理员请求权限。
Also you can use web.config transformations to automate the publish process. There is a "web.Release.config" file that is used by IIS when you publish your app (or in Release mode). Here is a good article from the asp.net official site.
您还可以使用web.config转换来自动执行发布过程。在发布应用程序时(或在发布模式下),IIS会使用“web.Release.config”文件。这是asp.net官方网站上的一篇好文章。