Detection of Folders - Directory Change

May 28, 2011 at 4:13 AM

I have your Photo Viewer setup on a VS2010 .aspx website, and it is working great. I noticed however, it is picking up my setup folders for my website, including my Scripts folder, Styles folder, and other Miscellaneous folder, because it is located in the root directory. I am using a SiteMaster to keep the website looking clean and all the same, is there any way to change the directory (within my website) from the root directory to a Photo directory for the album.ashx to search through and create the image files?

 

If any of this was confusing, please reply and I will clarify better.

 

Thank you for the great software, it was a learning experience for me.

Coordinator
May 28, 2011 at 4:17 AM

Yes, there is a bunch of settings at the beginning of the file that you can use for that sort of thing. If you are using it as a control, it is even easier as you just need to set a property on it.

May 28, 2011 at 4:21 AM

Settings in album.ashx? I have been looking and cannot find them for some reason, can you point me in the right direction if you have time? The file is in my root directory, and I want it to point to /Photo folder.

 

Thanks.

Coordinator
May 28, 2011 at 4:41 AM

The settings are the very first things in the file after the using statements and the namespace and class opening lines. But if you are using it as a control, you need to look at the properties inside the Album class.

May 28, 2011 at 7:20 PM

I noticed that I can change a few settings and relocate album.ashx to where I want, and if I load the album.ashx file itself in the url, it works correctly. However, if I use the following code it doesn't load it right for some reason.

Ignore the file names of Default, I have many files that I am testing different things with, and I cannot find how to get it to work correctly. I either get it to where it is loading the correct folders, but no images are loaded, or it works correctly independently, but not using the code below.

Any help is greatly appreciated, thanks.

<%@ Page Title="Images" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Src="~/Photo/album.ashx"   TagPrefix="Photo" TagName="album" %>

<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h1>
    <link rel='Stylesheet'  href="Styles/Album.css" type='text/css' />
</h1>
<body>
    <div>
        <photo:album runat="server" ID="Album1" />
    </div>
</body>
</asp:Content>

May 29, 2011 at 5:15 AM

This is what I have, and when I run that, I get an error. Any ideas?

 

<%@ Page Title="Images" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Src="~/album.ashx"   TagPrefix="photo" TagName="album" %>


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h1>
    <link rel='Stylesheet'  href="Styles/Album.css" type='text/css' />
</h1>
<body>
    <div>
        <photo:album runat="server" Path="~/Photo" HandlerUrl="~/album.ashx" ID="Album1" EnableViewState="false" />
    </div>
</body>
</asp:Content>

 

 

 

 

The error:

 

 

Value cannot be null.
Parameter name: value

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: value

Source Error:

Line 1576:                    }
Line 1577:
Line 1578:                    if (path != _requestDir && !path.StartsWith(_requestPathPrefix)) {
Line 1579:                        ReportError("invalid path - not in the handler scope");
Line 1580:                    }

 

Coordinator
May 31, 2011 at 10:41 PM

Did you try apecifying a Path property on the control?

May 31, 2011 at 11:35 PM

        <photo:album runat="server" Path="~/Photo" HandlerUrl="~/album.ashx" ID="Album1" EnableViewState="false" />?

 

In there I put Path="~/Photo"

May 31, 2011 at 11:47 PM

Changed to /website2/Photo as I saw what code was running through it in the debugger, but still fails.

Coordinator
May 31, 2011 at 11:58 PM

And in the debugger, _requestPathPrefix is null?

Jun 1, 2011 at 12:03 AM

Yeah.

 

 

 

I just put a webusercontrol.ascx and have

 

<%@ Register Src="~/WebUserControl.ascx"   TagPrefix="photo" TagName="album" %>

 

in my page, now nothing shows up.

Coordinator
Jun 1, 2011 at 12:33 AM

Can you put a breakpoint in Album.OnInit and see what's going on with the initialization of _requestPathPrefix?

Jun 1, 2011 at 12:40 AM

I don't believe it ever hits that. Let me check.

Jun 1, 2011 at 12:41 AM

I hits the error on line 1578. Never hits the OnInit method.

Coordinator
Jun 1, 2011 at 12:49 AM

That's a bug. Try to remove those three lines and see if it helps.

Jun 1, 2011 at 12:57 AM

Remove:

 


                    if (path != _requestDir && !path.StartsWith(_requestPathPrefix)) {
                        ReportError("invalid path - not in the handler scope");
                    }

 

?

 

If so, I got another null error

 

Line 1587:                ViewState["Path"] = path;
Line 1588:
Line 1589:                _physicalPath = _request.MapPath(path, "/", false);
Line 1590:            }
Line 1591:        }

Jun 1, 2011 at 1:00 AM

_request is not instantiated.

Coordinator
Jun 1, 2011 at 1:09 AM

You can use Server.MapPath.

Jun 1, 2011 at 1:18 AM

Okay so now it doesn't give me an error, but it doesn't load the right photo's, and it doesn't display images ><

 

"


                ViewState["Path"] = path;
            
                _physicalPath = Server.MapPath(path);

"

Jun 1, 2011 at 1:20 AM

Looking at the Debug, it goes through the first time correctly, then it goes back through using the root path for some reason.

Jun 1, 2011 at 1:23 AM

Okay just to make sure it isn't my code that is wrong, this is the web page that I have, the code.

 

<%@ Page Title="Images" Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<%@ Register Src="~/album.ashx"   TagPrefix="photo" TagName="album" %>


<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h1>
    <link rel='Stylesheet'  href="Styles/Album.css" type='text/css' />
</h1>
<body>
    <div>
        <photo:album runat="server"  HandlerUrl="~/album.ashx" ID="Album1" EnableViewState="false" Path="~/Photo"/>
    </div>
</body>
</asp:Content>

Jun 1, 2011 at 1:38 AM

If you have free time cool, if not, I understand. I am probably doing something wrong, I will try to tweak it and get results.

Coordinator
Jun 1, 2011 at 5:45 PM

Yeah, I'd need to reproduce and debug into it, which I can't do right now, and even I am a little confused about Path and other properties after all this time. I always have to go into the code and check. Maybe later this week I'll find some time to look into it. Let me know if you can make it work.

Sep 8, 2011 at 10:02 PM
bmcquarie wrote:

If you have free time cool, if not, I understand. I am probably doing something wrong, I will try to tweak it and get results.


Hi,

Please let us know if you get it working.  I, too was having my whole website's directory structure exposed with it, so I'm anxious to see if we can get it secured.

I did as you did for the variables "handlerUrl,Path etc". 

 

thanks

David