Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 为什么设置WebOperationContext.Current.OutgoingResponse.StatusCode=HttpStatusCode.Redirect会导致SecurityException?_C#_Rest_Exception Handling_Http Status Code 301_Securityexception - Fatal编程技术网

C# 为什么设置WebOperationContext.Current.OutgoingResponse.StatusCode=HttpStatusCode.Redirect会导致SecurityException?

C# 为什么设置WebOperationContext.Current.OutgoingResponse.StatusCode=HttpStatusCode.Redirect会导致SecurityException?,c#,rest,exception-handling,http-status-code-301,securityexception,C#,Rest,Exception Handling,Http Status Code 301,Securityexception,我正在使用.NET4中的Rest服务,需要执行重定向 对我所做的一点描述:我有一个silverlight应用程序,其中包含一个按钮。当我点击按钮时,我会向我的REST服务发送一个POST请求,其中包含一些信息。根据这些信息,我创建一个URL并(尝试)重定向浏览器。以下是服务中方法的代码: [WebInvoke(Method = "POST", UriTemplate = "OpenBinder")] public void OpenBinder(int someId) { string

我正在使用.NET4中的Rest服务,需要执行重定向

对我所做的一点描述:我有一个silverlight应用程序,其中包含一个按钮。当我点击按钮时,我会向我的REST服务发送一个POST请求,其中包含一些信息。根据这些信息,我创建一个URL并(尝试)重定向浏览器。以下是服务中方法的代码:

[WebInvoke(Method = "POST", UriTemplate = "OpenBinder")]
public void OpenBinder(int someId)
{
    string url = getUrl(someId);
    if (WebOperationContext.Current != null)
    {
        WebOperationContext.Current.OutgoingResponse.Location = url;
        WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.Redirect;
    }
}

这似乎执行正确,但当我在客户端调用EndGetResponse时,我看到发生了“安全错误”。这是System.Security.SecurityException,但我没有得到更多的细节。有什么想法吗?

没有更多信息,我不确定您的具体安全错误是什么,但通常在这种情况下,您的重定向应该发生在响应处理程序的客户端。你能重新构造你的代码使客户端重定向吗?

好的,这样我的代码实际上工作正常。当我查看Fiddler时,我注意到它正在向Url发出正确的请求。问题是ClientAccessPolicy.xml正在停止它。

您不能直接设置代码-请看,这是不正确的。否则他们就不会在属性上公开setter,尽管我明白你的意思。客户端重定向更可取,但我同意,url中的数据是敏感的,我们不希望传递的内容超过需要。