viewsVery Strange ASP.NET MVC and IE8 Link/URL Issue

down vote
favorite Hi folks, I’ve got a really strange issue in MVC/IE8 and I was wondering if anyone had seen anything like it. I’ve got a URL that returns an excel spreadsheet in the form http://application.mycompany/Controller.aspx/Action/ID1/ID2 (I am using the .aspx in the route due to the version of IIS). This opens from a page with the application, fine. I also have e-mails with HTML bodies that get sent around that have links in them and all the links open fine apart from this one - it gives an error saying “Cannot download ID2 from application.mycompany, IE was unable to open the site”. I’ve checked the HTML in the e-mail and the link location on the page that works and they are the same. If I type the exact link text (or copy and paste it from the e-mail) into the IE address bar it again fails, but then if I click on the same text in the addres bar at the end and hit enter a second time it loads and spits out the file. It seems to work ok pasting it straight into FireFox, but I can’t check clicking on the link and loading FF as I’m working remotely and don’t have Firefox on my citrix desktop, nor can I find anyone who has it as their default browser (but as it works first time, I would imagine it would be ok).

Has anyone seen this before or got any ideas what might be causing it, please? This issue occurs on more than one machine, so it isn’t an odd add-in/setting as far as I can see.

Thanks

MH

Just an update, this has been tested on another machine and this exact behaviour exists in IE, but if you change the default browser to chrome the link opens fine, first time.

I am not sure what the issue could be. But is it possible to be a problem with encoding or content type? Maybe if possible to post some code, maybe myself or someone else can help further.

Here’s the headers I’m returning

            Response.Cache.SetExpires(DateTime.UtcNow.AddDays(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.AddHeader("content-disposition", "attachment;filename=NewItemTemplate.xls");
            Response.ContentType = "application/vnd.ms-excel";

then it’s firing back html tables that are being loaded up by excel. I tried it with some test data and a straight controller/action URL and it worked fine, it’s only with a new URL it’s failing. Having tested it with firefox and chrome and it working fine it seems to be some sort of obscure IE bug,as far as I can tell.

The new URL is failing both from being typed in to the address bar and being clicked on via outlook. The other, really weird thing is there’s also a web page link to this page, if I click on it from the web page it works, if I right-click that link select copy shortcut and then paste that same link into the address bar it fails. If I then click the address bar and hit enter again, or select all and paste the link in again, it then works…??

#wtf

I don’t know the answer, but I noticed that you’ve copied and pasted this post at a load of different communities like StackOverflow and I’ve upvoted you on there in hope that someone will come across it and know the answer.

Good luck!

Thanks for that - yes, I’m getting desparate for an answer to this (though I suspect there won’t be one)

Try offering some of your reputation on StackOverflow as a bounty and I’m sure people will dive all over it. It’s typically how I get my questions answered when they’re largely ignored on SO.

maybe, trouble is I’ve got a nasty feeling there isn’t an answer to it so my bounty may well get wasted if people vote up an answer that isn’t actually correct (or does that not tend to happen on SO - sorry, I’m used to the ASP.NET forums where admins can post complete ******** answers and then mark themselves as the best answer, thus taking the bonus points for best answer)

You tried a http debugger yet? Would be nice to know exactly what the first request going out is . . .

Have you tried setting the content length response header?

It would be easier to help if you’d post the complete http response of both a failing request as well as a successful one.

I’m in the middle of something else very urgent ATM that can’t be interrupted, but I’ll see what debug info I can get when I have a minute. Is there a decent debug tool/addon for IE? - I have one for firefox, but firefox never exhibits this behaviour.

Sure. Fiddler is a great utility that can be used to inspect network traffic to and from browsers as well as other apps.

Thanks, I’ll get that loaded when I have a minute and post back some results.

Curiouser and curiouser - I used fiddler to look at the responses and they are identical, apart from the timestamp.

The server is sending the data back both times, but the first time IE decides that it isn’t getting it.

Failed Response:-

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/vnd.ms-excel; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 1.0
content-disposition: attachment;filename=Filename.xls
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 20 Dec 2010 10:31:52 GMT
Content-Length: 2354

<style type"text/css">.text { mso-number-format:\\@; } .TableHead { background-color: #BDBDBD; } </style>
....confidential file content removed

and the subsequent successful response:-

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/vnd.ms-excel; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.0
X-AspNetMvc-Version: 1.0
content-disposition: attachment;filename=Filename.xls
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Mon, 20 Dec 2010 10:32:18 GMT
Content-Length: 2354

<style type"text/css">.text { mso-number-format:\\@; } .TableHead { background-color: #BDBDBD; } </style>

Just to reiterate, all I do to generate the second request is click the text I’ve previously pasted into the address bar and hit enter, nothing else…
Cheers
MH

The error I get is "“Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later.”

As you’ve still not received an answer to your question and you were wary of using your bounty on SO I offered a bounty of 50 on your question. Hopefully someone somewhere will be able to give you an answer soon.

Thanks ever so much for that - I’ve literally just solved it, typical. Post this answer on stack overflow, let me know your user name there and I’ll select it so you get your bounty back.

It’s the caching, if you select no-cache IE can’t find the file to save it, but if you allow caching it works. Annoying as the same file can be downloaded at different times and may well be different if things have changed, so caching is a little dangerous (I’ll have to suffix the filename with a timestamp to avoid this, I think).
http://support.microsoft.com/kb/316431
so this fixes it
Response.Cache.SetCacheability(HttpCacheability.Private);
but it still doesn’t explain why it sometimes works, esp directly from the web page link

“This behaviour is by design” - translation “we can’t get this to work and CBA to get it working” - amazing how firefox, opera and chrome don’t have this problem…

Which versions of IE, windows, excel and outlook are we working with here?

Kinda a hunch, but try opening Excel then clicking on the link. Also try opening the link directly from excel’s file->open.

[My spidey sense says that some modal dialog or somesuch is making Outlook think IE fails to load the page but getting the error]

As far as I can see, the bug, errr, sorry, I mean “design feature” affects IE6+ (the MS article doesn’t seem to specify the version[s]) and is purely an IE issue rather than anything to do with outlook and excel

That’s cool. I posted the answer with a link back here as reference, but as far as I am aware it’s not possible to return bounty once it’s been given. It doesn’t matter too much anyway as 50 isn’t much.

Regardless, congrats on finding the source of your problems.