C# 远程处理 - 如何关闭自定义错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/209257/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# Remoting - How to turn off CustomErrors
提问by HAdes
I getting the following error when I try to connect to my server app using remoting:
当我尝试使用远程处理连接到我的服务器应用程序时,出现以下错误:
A problem seems to have occured whilst connecting to the remote server:
Server encountered an internal error. For more information, turn off customErrors in the server's .config file.
连接到远程服务器时似乎出现问题:
服务器遇到内部错误。有关详细信息,请关闭服务器的 .config 文件中的 customErrors。
This is the code on my server app:
这是我的服务器应用程序上的代码:
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
It seems to work the first time, but unless the server app is restarted the error occurs.
它似乎是第一次工作,但除非重新启动服务器应用程序,否则会发生错误。
I would guess something isn't being cleaned up properly but I'm not sure what as the customError is still on.
我猜有些东西没有被正确清理,但我不确定是什么,因为 customError 仍然存在。
Any ideas where I start. Thanks.
我从哪里开始的任何想法。谢谢。
[EDIT] - Thanks to Gulzar, I modified my code above to the following and now the errors are shown:
[编辑] - 感谢 Gulzar,我将上面的代码修改为以下内容,现在显示错误:
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
采纳答案by Gulzar Nazim
For .Net 1.0/1.1 , you need a config file for remoting server
对于 .Net 1.0/1.1 ,你需要一个远程服务器的配置文件
If you don't have a <ServerEXE>.config
file, create one and have this in it:
如果您没有<ServerEXE>.config
文件,请创建一个文件并将其放入其中:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<customErrors mode="off" />
</system.runtime.remoting>
</configuration>
For .Net 2.0, you can use RemotingConfiguration.CustomErrorsModeproperty
对于 .Net 2.0,您可以使用RemotingConfiguration.CustomErrorsMode属性
回答by DOK
To turn off customErrors, open the web.config file
on the server. If there is a customErrors
tag, change it. If there isn't one, add it.
要关闭 customErrors,请打开web.config file
服务器上的 。如果有customErrors
标签,请更改它。如果没有,请添加它。
It should be <customErrors mode="Off"/>
for this purpose.
应该是<customErrors mode="Off"/>
为了这个目的。
If you are indeed using a custom error page, you will want to change this setting once you've found your problem.
如果您确实在使用自定义错误页面,一旦发现问题,您将需要更改此设置。
回答by sometimes
In the server file, use:
在服务器文件中,使用:
RemotingConfiguration.CustomErrorsEnabled(bool);