HttpContext Problem

G

Guest

Hi,

I have a cutom HttpHandler to handle large file upload and it is having some
strange result.

It is working fine if I just load the upload page in Internet Explorer and
upload files.

However, there is a hyperlink on the upload page which open up another page
(on a different website) in a new IE window. If I click on the link which
open up another page and if I continue to upload file, it will fail.

The problem is GetPreloadedEntityBody is returning null. If I check the
Request.ContentLength and Request.Files.Count of the HttpContext, both are
return zero.

Can someone please kindly help me on this?

Thanks,
Alex
 
W

Walter Wang [MSFT]

Hi Alex,

Would you please tell me more about this issue, such as:

1) Which ASP.NET version you're using?
2) Which IIS version you're using to run the web site?
3) Does this issue occur when uploading a small file?
4) What's your custom HttpHandler doing?
5) Does it reproduce using a simple web project? If it does, would you
please send it to me?

I'm sorry I have to ask these questions first before give any suggestion on
what might be wrong.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Walter

1) Both .Net 1.1 and 2.0 were installed on the server. But this application
was configured to use 1.1.
2) Windows 2003 with II6.
3) Error happens regardless of file size.
4) Please see below code.

protected HttpWorkerRequest GetWorkerRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)context;
return (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
}



public void ProcessRequest(HttpContext context)
{

if (context.Request.ContentType.ToLower().StartsWith("multipart/form-data"))
{
HttpWorkerRequest worker = GetWorkerRequest(context);

if (worker != null)
{
string boundary = ExtractBoundary(context.Request.ContentType);
MultipartParser parser = new MultipartParser(new RequestStream(worker),
boundary, context.Request.ContentLength);

string uploadId =
context.Request.QueryString[ConfigurationSettings.AppSettings["uploadId"]];

if (uploadId != null)
RegisterIn(context.Application, parser, uploadId);

parser.Parse();

string param = parser.param;
context.Response.Redirect(context.Request.FilePath+"?"+
ConfigurationSettings.AppSettings["uploadId"] + "=" + uploadId +param);
}

}

}




public bool IsReusable
{
get
{
return false;
}
}

Below is the RequestStream's constructor.

public RequestStream(HttpWorkerRequest request)
{
_request = request;

_isPreloaded = true;
buff = _request.GetPreloadedEntityBody();
buffSize = buff.Length;
EndOfStream = false;
}

The stack trace stop at buffSize=buff.Length with the error "Object
reference not set to an instance of an object.".

Thanks,
Alex
 
B

bruce barker

if the user hits the link, the file is not uploaded, but its still
multipart form postback, just no file. you code shoudl handle this case.

-- bruce (sqlwork.com)
 
G

Guest

Hi Bruce,

The link open up another page that is nothing to do with the file upload.
It is a registration page hosted in a different "IIS Virtual Directory" and
it is not handle by the custom handler. The problem is once the link is
being clicked, any attempt to upload files will fail until I close all IE
windows that are running in the same IEXPLORER.exe process.

Thanks,
Alex
 
W

Walter Wang [MSFT]

Hi Alex,

Sorry for late reply.

I've done some local tests, tried in IE6 and IE7, unfortunately I'm not
able to reproduce the issue you described. Here's my test steps:

1) Create an ASP.NET 1.1 web application
2) WebForm1.aspx:

<form action="WebForm2.ashx" enctype="multipart/form-data" method="post">
<input type="file"> <input type="submit">
<a href="http://www.microsoft.com/" target="_blank">external</a>
</form>

3) WebForm2.ashx:

<% @ webhandler language="C#" class="Class1" %>

using System;
using System.Web;

public class Class1 : IHttpHandler
{
protected HttpWorkerRequest GetWorkerRequest(HttpContext context)
{
IServiceProvider provider = (IServiceProvider)context;
return (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
}

public void ProcessRequest(HttpContext context)
{
if
(context.Request.ContentType.ToLower().StartsWith("multipart/form-data"))
{
HttpWorkerRequest worker = GetWorkerRequest(context);

if (worker != null)
{
byte[] buf = worker.GetPreloadedEntityBody();
context.Response.Write(buf == null ? "buf is null" : "buf is not null");
}
}
}

public bool IsReusable
{
get { return false; }
}
}


Would you please help me test this on your side and let me know the result?
Also, have you tried using other browsers on your side?


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Walter,

The result is "buf is not null". I have not tried on other browsers.

I save the whole context into a text file and I notice that when it does not
work, the following line will appear as one of the headers.

Authorization: Negotiate
TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAFASgKAAAADw==

Does this make any sense to you?

Thanks,
Alex
 
W

Walter Wang [MSFT]

Hi Alex,

The "Authorization: Negotiate" header is used for Kerberos authentication
in IE and IIS, this normally means you've checked "Integrated Windows
authentication" in IIS virtual directory security settings. If you use
Fiddler (http://www.fiddlertool.com/) to trace the http request/response
headers, you will see this. Per the issue here, I'm not sure it's related
since it seems a normal one if you're using Integrated Windows
authentication.

Given that the simple test doesn't reproduce the issue on your side either,
I'm afraid you will have to create the reproducible project on your side.
Here's some suggestion to narrow down from your existing web app:

1) You mentioned that the external web site is on the same server in
another virtual directory, what if we change this external link to other
URL, such as "about:blank", does it have impact on the result?

2) Given that you're using Integrated Windows authentication, what if we
enable Anonymous user? (I've tested it using the same test project with
Integrated Windows authentication but it still doesn't reproduce)

I'm not sure if my test method is similar to your real application or not.
It would be great if we could figure out how to reproduce it using a
simpler app.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

Hi Walter,

I think my description of my setup was incomplete. Below is how it looks
like.


TreeView of IIS 6:

Internet Information Services
|
HostName
|
Application Pools
| |
| Pool1
| |
| UploadFileApps
| getEmailAddressApps
| Pool2
| |
| RegistrationApps
|
Web Sites
|
Site1
|
UploadFileApps -> Anonymous authentication (using domain account)
getEmailAddressApps -> Integrated Authention
RegistrationApps -> Integrated Authention


UploadFilesApps and getEmailAddressApps are .Net 1.1 apps. RegistrationApps
is .Net 2.0 app.

When user access UploadFileApps, it will check whether the user's email
address has been captured. If not, it will be redirect to
getEmailAddressApps, get the email address from AD and redirect back to
UploadFileApps. At this moment, if the user upload file(s), there is no
problem. However, if the user click on the link which open up the
RegistrationApps, the upload will fail.

However, I do notice if the link is outside of the same website (in this
case Site1), it is okay.

Thanks,
Alex
 
W

Walter Wang [MSFT]

Hi Alex,

Does clicking the link which opens up the RegistrationApps cause a postback
to your Upload page? In other word, is it a simply <a href="..."
target="_blank"> or it's a server control that needs postback to make it
open an external window?

If this is purely client-side hyperlink, then it's probably related to the
client browser, would you please help me to test it using other versions of
IE or other browsers to verify if this behavior is browser-specific issue.

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top