C# 远程处理 - 如何关闭 CustomErrors
当我尝试使用远程处理连接到我的服务器应用程序时,出现以下错误:
连接远程服务器时似乎出现问题:
服务器遇到内部错误。 有关详细信息,请关闭服务器的 .config 文件中的 customErrors。
这是我的服务器应用程序上的代码:
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
它似乎第一次工作,但除非重新启动服务器应用程序,否则会发生错误。
我猜想有些东西没有被正确清理,但我不确定什么,因为 customError 仍然存在。
我从哪里开始的任何想法。 谢谢。
[编辑] - 感谢 Gulzar,我将上面的代码修改为以下内容,现在显示错误:
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
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.
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.
Any ideas where I start. Thanks.
[EDIT] - Thanks to Gulzar, I modified my code above to the following and now the errors are shown:
RemotingConfiguration.CustomErrorsMode = CustomErrorsModes.Off;
TcpChannel tcpChannel = new TcpChannel(999);
MyRemoteObject remObj = new MyRemoteObject (this);
RemotingServices.Marshal(remObj, "MyUri");
ChannelServices.RegisterChannel(tcpChannel);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要关闭 customErrors,请打开服务器上的
web.config 文件
。 如果存在customErrors
标记,请更改它。 如果没有,请添加。为此,应将其设置为
。如果您确实使用自定义错误页面,那么在发现问题后您将需要更改此设置。
To turn off customErrors, open the
web.config file
on the server. If there is acustomErrors
tag, change it. If there isn't one, add it.It should be
<customErrors mode="Off"/>
for this purpose.If you are indeed using a custom error page, you will want to change this setting once you've found your problem.
对于 .Net 1.0/1.1 ,您需要一个用于远程处理服务器的配置文件。
如果您没有
.config
文件,请创建一个文件并在其中包含以下内容:对于 .Net 2.0,您可以使用 RemotingConfiguration.CustomErrorsMode 属性
For .Net 1.0/1.1 , you need a config file for remoting server
If you don't have a
<ServerEXE>.config
file, create one and have this in it:For .Net 2.0, you can use RemotingConfiguration.CustomErrorsMode property
在服务器文件中,使用:
In the server file, use: