开发者

Using Silverlight 4 WebClient OpenReadCompleted throughs Security Exceptions on hosted web server. What's the pronblem?

Seems to be a simple thing using a WebClient object to retrieve content of a text file in a Silverlight web application.

It works in our intranet setup on a local server, but when deployed on a hosted "hostgator" ser开发者_如何学Gover, WebClient gets a security exception. Following suggestions from numerous web blogs, I tried crossdomain access policy and crossdomain.xml with no result - no wonder, all in on the same domain.

    private void LoadCSVFile(string csvFile)
    {
        try
        {
            WebClient client = new WebClient();

            client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
            client.OpenReadAsync(new Uri(csvFile, UriKind.Absolute));
        }
        catch (Exception ex)
        {
            string errorMessage = String.Format("Ex accessing csv: {0}\n{1}", csvFile, 

} }

//the csvFile is an absolute path: http://myserver.com/myapplication:port/sourcefiles/file.csv //The sourcefiles is a virtual directory in the same website containing csv files

    void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        if (e.Error == null)
        {
            try
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(e.Result))
                {
                    mainFileData = new List<string>();
                    string line;
                                        }
            }
            catch (Exception ex)
            {
                string errorMessage = ex.InnerException;

}else { "here is the place for the exception!!!!!!! so, e.Error is not null" } }

The text of the exception reads: System.SecurityException: Security error at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult) etc.

Spend 2 days gooogling with no result.

Please help. V


A couple of things to check:

(1) The format for the URL that you list (http://myserver.com/myapplication:port/sourcefiles/file.csv) looks odd. Shouldn't it be http://myserver.com:port/myapplication/sourcefiles/file.csv? Or is that just a typo?

(2) What's the port number that you're accessing? The Silverlight WebClient will only access ports 80 and 443.

(3) Can you get to the file using a direct URL? Sometimes web servers need to be told about a specific file type before they'll allow it to be served up.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜