0

Architecture of my "ImageDemo" application

Technology : ASP.NET Language : C#

Previous architecture: The asp.net pages are stored in the webserver. A folder named ImageRepository is exist in the webserver. I do store the images (browsed, selected, and stored by users) in the ImageRepository. I could access all the attributes and content of the images stored in ImageRepository. I used to display images using Image control of ASP.NET.

New architecture: Instead of storing the images in a folder of the webserver, I do setup a dedicated Files Server with the following credentials(say)

user name : my_name

password : wXy12Apl

I could login to the system, access the folder where I stored the images, read the all attributes of the files. Then I added the file name to a dropdown list,so it will look ;like this

enter image description here

So on the onselectedindexchanged event I tried to display the images using Image control of ASP.NET. But I could not. What will be the problem? I could access all the attributes of the files, but I could not read the content of image.

For eg; When I select first image, the contol looks like enter image description here

When I select second image, the contol looks like enter image description here

1
  • 1
    Post some relevant code please. Commented Jun 6, 2011 at 8:27

2 Answers 2

1

You may not have permission to the file. You can do like @Smudge202 suggests and apply the correct permissions, or you can run part of your code in a different context. See this code for impersonating a user: http://www.codeproject.com/KB/cs/zetaimpersonator.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

The browser / end-user does not have access to the file server. There are a couple quick solutions you can implement:

1) Add permission for end users to read from the new file share - if your site is internal (on a LAN only) then this is possibly the best solution. If the site is exposed to the internet this may not prove to be the most secure solution.

2) Create a simple web service (WCF or ASMX). Ensure the service can read from the new share, and have the service return the content as a webresponse.

Here is an (almost complete) example of the latter, an old piece of code responding from the old style asp.net handler (ashx) which implements IHttpHandler - I'd recommend using WCF personally:

Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    _Context = context
    _Context.Response.Clear()
    _Context.Response.ContentType = "image/jpg"
    If ImageParameter IsNot Nothing Then

        Dim imageData As Byte() = Nothing
        If String.IsNullOrEmpty(ImageParameter.CompressedFileStorageLocation) Then
            Return
        End If

        Dim imagePath As String = String.Format("{0}{1}", CS_IMAGE_REPOSITORY_BASE_PATH, ImageParameter.CompressedFileStorageLocation)
        Try
            If IO.File.Exists(imagePath) Then
                Using s As FileStream = New FileStream(imagePath, FileMode.Open)
                    ReDim imageData(s.Length)
                    Dim bytesRead As Integer = s.Read(imageData, 0, s.Length)
                    s.Close()
                End Using
            End If
        Catch ex As Exception
            Debug.Print(ex.Message)
        End Try

        _Context.Response.OutputStream.Write(imageData, 0, imageData.Length)
    End If

End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.