IIS 7.5 - Lightswitch - Sample Code - Path Null error

Jun 17, 2012 at 6:11 AM

I am having an issue with file upload after I publish the Lightswitch Sample to an IIS 7.5 server. 

I know this has been covered extensively in the forum and I am sure I am missing something but have run out of ideas.

All works fine in the my dev environment using Cassini - uploads work fine - directories are created in bin directories etc. 

When I publish the same app (as a package) and try to upload a small file (140K) I get a Messagebox with the title "Upload Completed" and the messsage "Upload completed with errors or some files canceled" 

Using Fiddler to get at the error I get:

Server Error in '/Application1' Application.

Value cannot be null.
Parameter name: path

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: path

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[ArgumentNullException: Value cannot be null.
Parameter name: path]
   System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption) +12812485
   HSS.Interlink.Web.BaseHandler.PurgeTempFiles(String folder) +70
   HSS.Interlink.Web.BaseUploadHandler.HSS.Interlink.Web.IUploadHandler.Upload(HttpContext context, FileQuery query) +3552
   HSS.Interlink.Web.FileUpload.ProcessRequest(HttpContext context) +119
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270



 

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

 

I have updated the web.config file as follows:

  <appSettings>
    <add key="UploadHandler" value="LightSwitchApplication.UploadHandler, Application.Server" />
  </appSettings>

 

    <httpHandlers>
      <add verb="GET" path="trace.axd" type="Microsoft.LightSwitch.WebHost.Implementation.TraceHandler,Microsoft.LightSwitch.Server.Internal,Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <!-- <add verb="GET,POST" path="FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" /> -->
    </httpHandlers>

 

    <handlers>
      <!-- LightSwitch trace.axd handler -->
      <add name="LightSwitchTrace" path="trace.axd" verb="*" type="Microsoft.LightSwitch.WebHost.Implementation.TraceHandler,Microsoft.LightSwitch.Server.Internal,Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      <add name="FileUpload" verb="GET,POST" path="Application1/FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" />
    </handlers>

 

I have declared a UploadUri as follows in client:

        d.UploadUri = "Application1/FileUpload.ashx";

 

Other relevant info:

I am using the Lightswitch sample app as is - no changes (except UploadUri)

Using ASP.NET v4.0 Application Pool on IIS 7.5 set to Integrated Mode

App name is Application1 installed as application under default website so relative path is Application1 - so I think the web config changes are correct. (app is called via http://192.168.1.200/Application1)

Have created the InterLink/Uploads directory under Application1 directory as per the standard UploadHandler FileStoreFolder and given NetworkService user full permissions to directory - also enabled browsing on this directory.

Am really quite stumped now - searched forum and read everything without luck.

Could this be a permissions issue with the temp directory?

Any Help?

Best Regards,

Chris

Coordinator
Jun 17, 2012 at 7:18 AM

First, I must comment on the complete diagnostics, makes life much easier and greatly appreciated.

OK, I think the issue maybe the client side UploadUri. I vaguely remember this issue with another dev.

Try just d.UploadUri = "FileUpload.ashx"; with no forward slash in front or include the slash d.UploadUri = "/Application1/FileUpload.ashx";

You can also try changing in the handler section as well: "/Application1/FileUpload.ashx" or "FileUpload.ashx"
If you choose the later, that will resolve no matter what the app hierarchy, as there is no leading slash, so any request from Default on down that ends with FileUpload.ashx, the Interlink http handler will be called. The only reason to add the "/Application1/FileUpload.ashx" or "/FileUpload.ashx" is to ensure it's only called from the appropriate site/app. 

Good luck, and let us know if you get it working or if you need more assistance.

Jun 17, 2012 at 8:58 AM

Hi, thanks for the rapid response.

I have tried changing the UploadUri in the client as suggested - to just FileUpload.ashx and then /Application1/FileUpload.ashx secondly - the same error is being generated with both options.

Where would I change the UploadUri it in the handler section as suggested? I cannot see any logical place in the UploadHandler file to set this.

Best regards,

Chris

 

Coordinator
Jun 17, 2012 at 6:04 PM

sorry for the confusion, the handler section in the web config.

<add name="FileUpload" verb="GET,POST" path="FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" />
<add name="FileUpload" verb="GET,POST" path="/Application1/FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" />

Depending on your environment, you may have to play with these settings.

To confirm, on the client side, the UploadUri property is merged with the current URL of your page.
So if your page is http://some.com/app/page1.aspx, an UploadUri of "filehandler.ashx"
would become http://some.com/app/filehandler.aspx and an UploadUri of "/filehandler.ashx"
would become http://some.com/filehandler.aspx

So your http handler path in the web config should be "/app/filehandler.aspx" for the first example OR
"/filehandler.ashx" for the second or just "filehandler.ashx" for any



Jun 19, 2012 at 4:44 AM
Edited Jun 19, 2012 at 4:46 AM

Still can't seem to get this to work - have tried this on our internal server and a prod server just to make sure it wasn't something specific with our dev server.

I have tried all suggested combinations of UploadUri and web config handler without luck. I can confirm I am executing the filehandler on the server but it looks like I am hitting something in the PurgeTempFiles function of the basehandler. And it looks like the path is not being set on the call to this function but that could just be masking something else.

It is clearly a config type error otherwise it wouldn't be working on my dev machine under Cassini but I need to see what is going on inside the handler.

Looking at the source for the uploadhandler there doesn't appear to be any logging unless I am missing something.

Would you have any suggestions as to how I might be able to get a trace of the uploadhandler execution so I can pinpoint where an upload request is falling over?

Also, I am using v2.2.100 of Interlink - would using the v3 libraries be a better option.

Really appreciate your help so far.

best regards,

Chris

Coordinator
Jun 20, 2012 at 5:03 AM

Sorry for the delayed response.

1. Sounds like a file permissions issue
Ensure the identity of your app pool has full permissions on your app folder (Read/Write/Delete etc.)

2a. You can override the OnError method in your file handler to receive errors
2b. You can look in the local machine event log of your IIS Server under ASP.NET and you should see error details

3. You can upgrade to v3.0 if you're running SL5 (I think LightSwtich is still on SL4)
Caveat to using v3 is there is no more default ChildWindow as the main control as in v2, it's now just a UserControl

Jul 24, 2012 at 1:09 AM
Edited Jul 24, 2012 at 1:12 AM

I've noticed the NUGET package for HSS Interlink that generates upload/download handlers, sets

  <appSettings>
    <add key="UploadHandler" value="AudioUpload.Web.UploadHandler" />
  </appSettings>

whereas at the sourcecode example I've seen:

  <appSettings>
    <add key="UploadHandler" value="AudioUpload.Web.UploadHandler, AudioUpload.Web" />
  </appSettings>

//where AudioUpload.Web is my web app's default package
Jul 24, 2012 at 1:15 AM

Btw, above it's mentioned that NETWORK SERVICE is given permissions for the Uploads (or whatever the UploadHandler defines) folder. I'd expect that the account "IIS APPPOOL\DefaultAppPool" would be used instead. Or do .ashx handlers don't run in the apppool defined for the web app?

Coordinator
Jul 24, 2012 at 1:20 AM

you only need to include the assembly name if your handler class is in a separate dll assembly and is dropped into the bin folder. If it's part of your web applications dll, then it's not necessary.

As far the AppPool identity, most people get confused when I talk about the IIS AppPool\[AppName]Pool and they typically just use NETWORK SERVICE because that's what they're used to. But you are correct the AppPool identity whatever it is, needs to have read/write permissions and no ASHX run inside the app pool process with it's identity.

Jul 24, 2012 at 1:36 AM

btw, this is relevant to the AppPool discussion above: http://adopenstatic.com/cs/blogs/ken/archive/2008/01/29/15759.aspx

Coordinator
Jul 24, 2012 at 5:29 AM

I dont run more than one web aplication per site/app pool so I don't have those worries. Each Site/App has it's own AppPool and therefore it's own Sid.

Jul 24, 2012 at 1:16 PM

btw, at the web.config cmacdonalnd1971 posted above I see

 <add name="FileUpload" verb="GET,POST" path="Application1/FileUpload.ashx" type="HSS.Interlink.Web.FileUpload, HSS.Interlink.Web" />

mine (which doesn't work) says:

   <add name="FileUpload" verb="GET,POST" path="FileUpload.ashx" type="HSS.Interlink.Web.FileUpload" />
  

do I need the second part? (is it similar response with the <add key="UploadHandler"... I was asking a bit above in this discussion, or is it a typo?)

Coordinator
Jul 24, 2012 at 1:22 PM

Yes, to correct my prior comment, yes you need to specify the Assembly Name for your AppSetting

<add key="UploadHandler" value="AudioUpload.Web.UploadHandler, AudioUpload.Web" />

Also, make sure you have the correct handler section. For VS Dev Debugging/IIS6/IIS 7 Classic Mode, you use the httpHandlers section under the system.web section.

For IIS/Express 7/8 with Integrated Mode you use the handlers section under the system.webserver section