generic error, saving to unc path

Last post 06-16-2005 7:25 AM by JasonFollas. 3 replies.

Sort Posts:

  • generic error, saving to unc path

    06-14-2005, 11:15 PM
    • Member
      150 point Member
    • BioMash
    • Member since 08-20-2002, 8:43 AM
    • Western Australia
    • Posts 30
    Hi I have the folloeing code and I am trying to save the image to 2 different locations. one locally and one on a network share accross a vpn, I have checked permissions and they seem to be fine, I have also tried a seperate stream after reading another thread but I am always getting the same error. I also tried setting up a virtual directory in IIS and then using serv.mappath, but it always returned a local path rather than the network share!!

    Some help would be appreciated.

    <code>

    string strFilePath = Server.MapPath(Request.ApplicationPath + "/images/client/" + strClientLastNameLetter + "/");

    string str2ndPath = @"\\192.168.0.252\ssnet\images\client\" + strClientLastNameLetter + @"\";

    HttpFileCollection HttpFiles = Request.Files;

    ArrayList aryPhoto = Photo.GetPhotoByClient(intClientID);

    int j = aryPhoto.Count;

    for (int i = 0; i < HttpFiles.Count; i++)

    {

    HttpPostedFile imgCurrentFile = HttpFilesIdea [I];

    try

    {

    if (imgCurrentFile.ContentLength > 0)

    {

    string strPath = strFilePath + objClient.ID + "_" + (j + 1) + "_temp.jpg";

    imgCurrentFile.SaveAs(strPath);

    Photo objPhoto = new Photo();

    objPhoto.ClientID = intClientID;

    objPhoto.Face = 0;

    objPhoto.Date = dtePhotoDate;

    objPhoto.Name = objClient.ID + "_" + (j + 1);

    objPhoto.Notes = "";

    objPhoto.OperatorID = intOperatorID;

    int intPhotoID = objPhoto.Update();

    System.Drawing.Image objImage = System.Drawing.Image.FromFile(strPath);

    string[] strDecimal;

    char chrDecimal = char.Parse(".");

    double dblHeight = double.Parse(objImage.Height.ToString());

    double dblWidth = double.Parse(objImage.Width.ToString());

    double dblSmallRatio = dblWidth / 120;

    double dblSmallHeight = dblHeight / dblSmallRatio;

    string strSmallHeight = dblSmallHeight.ToString();

    strDecimal = strSmallHeight.Split(chrDecimal);

    strSmallHeight = strDecimal[0];

    int intSmallHeight = Int32.Parse(strSmallHeight);

    System.Drawing.Bitmap objBitmap = new Bitmap(objImage, 120, intSmallHeight);

    objBitmap.Save(strFilePath + objClient.ID + "_" + (j + 1) + "_TN.jpg", objImage.RawFormat);

    objBitmap.Save(str2ndPath + objClient.ID + "_" + (j + 1) + "_TN.jpg", objImage.RawFormat);  <-- error occurs here (a generic gdi+ error has occured

    objImage.Dispose();

    objBitmap.Dispose();
    </code>

  • Re: generic error, saving to unc path

    06-15-2005, 11:41 AM
    • Participant
      860 point Participant
    • JasonFollas
    • Member since 06-02-2005, 2:13 PM
    • 41.501000, -83.718000
    • Posts 170
    When you say that you checked permissions and they seem fine, what does that mean in terms of your ASP.NET worker process userid?  Meaning, by default ASP.NET runs as a local user called ASPNET, which likely doesn't have any rights outside of the machine that your webserver runs on.

    One workaround that I've seen is to use a domain account for the worker process.  I'm not sure if I necessarily agree with that practice (haven't thought too much about it), but it works for what my client was trying to do.

    Another workaround might be to create a local ASPNET account on your fileserver, and ensure that the passwords for ASPNET match on both the web server and the fileserver. 
  • Re: generic error, saving to unc path

    06-15-2005, 10:06 PM
    • Member
      150 point Member
    • BioMash
    • Member since 08-20-2002, 8:43 AM
    • Western Australia
    • Posts 30

    Thanks for the input, I will give it a go. I thought that giving permissions to everybody should have solved the problem....but I must be wrong.

    One of the machines is running 2003 server and one is running 2000 server so I will try and recreate the aspnet user on each machine. Does asp.net worker process run as same user on both OS?

  • Re: generic error, saving to unc path

    06-16-2005, 7:25 AM
    • Participant
      860 point Participant
    • JasonFollas
    • Member since 06-02-2005, 2:13 PM
    • 41.501000, -83.718000
    • Posts 170

    Yeah, it's a very common misconception that you can just grant permissions to the "Everybody" group and all will be fine.  Doing so definitely doesn't handle as many scenarios as you think (this being a case in point).

    As far as I'm aware, you can set a manual password for the ASPNET account (in order to synchronize the accounts on both machines), but you'll also need to edit your machine.config file to store that password instead of "AutoGenerate".

    <processModel enable="true" timeout="Infinite" idleTimeout="Infinite" shutdownTimeout="0:00:05" requestLimit="Infinite" requestQueueLimit="5000" restartQueueLimit="10" memoryLimit="60" webGarden="false" cpuMask="0xffffffff" userName="machine" password="AutoGenerate" logLevel="Errors" clientConnectedCheck="0:00:05" comAuthenticationLevel="Connect" comImpersonationLevel="Impersonate" responseDeadlockInterval="00:03:00" maxWorkerThreads="20" maxIoThreads="20"/>

    If you ever need to go back to the autogenerated password, then you'll have to run Aspnet_regiis.exe.

Page 1 of 1 (4 items)