PictureBox and URI Value

2 posts, 0 answers
  1. Louis
    Louis avatar
    85 posts
    Member since:
    Jun 2011

    Posted 01 Sep 2019 Link to this post


    I got a PictureBox that the URI is a call to an action method :

    ="https://mysite.com/Stocks/Dwnlod/" + CStr(Fields.PhysicalName)


    I use ASP.NET MVC Core and my pictures are not in wwwroot.  They are under another directory of the project.

    So I use a method to get the filestream of the file :

    public async Task<FileStreamResult> Dwnlod(string id)
        var memory = new MemoryStream();
            using (var stream = new FileStream(path, FileMode.Open))
                await stream.CopyToAsync(memory);
        catch (Exception e)
        memory.Position = 0;
        return File(memory, GetContentType(path), Path.GetFileName(path));


    As you can see my action method is decorated [Authorize] so it's impossible to get the stream from the report even if the user is connected and authenticated.  The call of URI from the report seem be anonyous.  So i got a error (of course everything works #1 when I remove the decoration Authorize).


    Any suggestion to keep [Authorize]?  Can the report can provide some authenification when the URI is called?


    Thank you all of you at Telerik.



  2. Neli
    Neli avatar
    365 posts

    Posted 04 Sep 2019 Link to this post

    Hello Louis,

    The reports are generated on the server. In this scenario, the application must have access to the specified resource. In general, when you provide an URL as a PictureBox.Value, we use a WebClient to download the image. At that point, the connection to server fails with the statement that the application's process is not authorized to get the resource.

    What actually do you return from Dwnlod method? Is it the report or the picture?

    You can test to create a User Function that will download the image after authorizing and returns it (e.g. as type Bitmap) for the picture box value.

    The User Function (without authorization) might look as follows:

    public static Bitmap GetImage(string url)
                System.Net.WebRequest request = System.Net.WebRequest.Create(url);
                System.Net.WebResponse response = request.GetResponse();
                System.IO.Stream responseStream = response.GetResponseStream();
                Bitmap bitmap = new Bitmap(responseStream);
                return bitmap;


    Note that it will be necessary to authorize the request to successfully download the image from the URL.


    Progress Telerik

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top