local host site, outputting random text - asp.net

I started to do some updates to a site this morning, and when I went to run it, I am getting random text instead of the site.
The site is setup on a local url, mysite.local, with an entry in hosts to map it to my PC.
I have tried a "clean and rebuild" in VS, IIS Reset, Recycling the app pool, re booting the PC, and even creating a new entry in IIS, but nothing solves it.
It only appears to be happening on aspx pages, as I can load .htm pages without error.
I need to get some updates done today, so any help would be fantastic!
Here is the text it's outputting
���`I�%&/m�{J�J��t��`$ؐ#�������iG#)�*��eVe]f#�흼��{����{����;�N'���?\fdl��J�ɞ!���?~|?"��Ey�')=��y6�����h���ly���,�&?�O�t�-���7������bU���'/���lR��_�|�fm�&_��W���fmQ-��Ǐ� 0z�^��jv����j�n�g���~��O��,[f��Wyq1o-�z���QS� �����iUV��I�M���ԃ�z�>�EV_���Z=J���������T���������f�����Z���gir�k�ܷ ��ZPWu������e� �tU� \g�a��_��y��� �J�����ߵ۳|Z��B��e��P�y��W�/�/��:l��uE})�'U�V�G����]�ݻU��e��F�v{^/gy]�{�#����.���u��su�S��]���U1�?��'賏��E�d�� B����w�^�5�;=������������������vwv~���ٮ��YS���������|�(}\|S�^a�{�c�� �Lϳi��G�u�����9!��Q�y��/�����u�l�_��2�Gi����.���&G�Ӽ���J8������2]/1#%�F�n��wi5�ɂ���u��H�yN��ӵ|{�pB�*��u���yӎӗe�59�}Y�Wܬi�_Ӷ������")���*�M�u+]��6��^ξ��K��-ۄ񥌷������[u�j�ܢ�?���eA��v����hp�t1�6��|x����ٚѯ�[���.i�����bU���f]���6����M���<|x�40b�gŲh��,ǹ���A���ClY�y��_2�����t���������$h�[��홈�zD�pM���ziI��f��r*��=|x��!��b�$\�����ҧ�c�(����w<[�y��JE�E���u^_o��v:A���l���M��X�����M�u���x���|2~�7�S�{�613C� L �h�C��Š�䧍��r�i4��)����� �����?�����;����-%q1�����buHF,I����:��j ��*g����#MW�m�̷�ݶ+��;yO��N60�Ì���C�:!����!�.�+����nF����j�.sR��&�e4�B�����踾h���F�>�{�-��W�.���ϲ�rk~�.��F���6�ʭ1��pUn�y�Q��yK�u}�����ug�V7:2���z��qanD��p`"�t�oΝ�Eg��f�<��8��>�P=�j
The latest thing I have tried is to bring down the code from svn into a brand new folder, create a new entry in IIS and point at this. I am still getting the same issue after this!!
Also, other sites running locally are not getting the error.

Looks like you have enabled gzip.
In your Application_Error make sure you remove the custom response filter:
protected void Application_Error(Object sender, EventArgs e)
{
HttpApplication app = sender as HttpApplication;
app.Response.Filter = null;
}
Rick Strahl described the problem in more details in his blog post.

Right, problem solved!
I turned out to be an issue with my session tables.
I followed the steps outlined in this post, and it solved my problem:
http://forums.asp.net/t/1313929.aspx/1

Related

Sounds included in Web Application not Playing in IIS

I create this web application that provides sound whenever the number in the window changes. When I run my application in Visual Studio, The sound perfectly works but when I open my web with IIS 7, the sound doesn't work anymore.
What causes this? And How can I solve it?
I'm using ASP.Net by the way.
thanks for immediate response.
This is the code that i use
public void providesound()
{
System.Reflection.Assembly a =System.Reflection.Assembly.GetExecutingAssembly();
System.IO.Stream s = a.GetManifestResourceStream("~/sound/beep.wav");
SoundPlayer player = new SoundPlayer(s);
player.Play();
}
Since the sound is playing in your dev environment the only reason I can think of for sound not playing when deployed in IIS is that; your IIS is not configured to send the sound file across to the client. In simple words if you have a sound file say with .wav extenstion, in IIS under MIME Types of you website see if you have an entry for this extension. If not the following link can help you create the MIME entry:
http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx
I believe this would solve your problem, but if not then you should post the code as asked by Damien and also add the details about how you are publishing your site (step by step).
Edit 1:
Looking at the code that you are using I dont think you can make the sound work that way on your client. here are two link refer them: asp.net SoundPlayer not playing from server , How to run a .wav in client. ASP.NET
Hope this helps.
I'm able to accomplish this task by creating a Javascript
function EvalSound(soundobj)
{
var thissound = document.getElementById(soundobj);
thissound.play();
}
<audio id="audio1" src="Sound/beep.wav" controls preload="auto" autobuffer HIDDEN=true >
and in my .cs
public void CreateSound()
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(#"<script language='javascript'>");
sb.Append(#"EvalSound('audio1');");
sb.Append(#"</script>");
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "JCall1", sb.ToString(), false);
}
You can add the CreateSound() in Button_Click.

What happened to my ASP.NET website causing NullReferenceException in code behind on controls from MasterPage?

I have the strangest problem! I have an ASP.NET website application (luckily not yet live). Yesterday and everyday before, I could run the application without error. It was working fine when I turned the computer off late last night. When I ran the application today, I got a strange message telling me that my website was offline and that I should remove the app_offline.htm page from my root directory to put it back online.
I have never seen this message or page before, so I searched online to find that apparently SQL Server can put it there temporarily while it's busy to stop any more incoming requests (or something similar). Its proper use is to stop requests going to your site when you are updrading or doing maintenance. I proceeded to remove it as suggested. I cleaned and built the solution and then tried to run it. It no longer runs.
Now, I get an error in my MasterPage code behind where I normally access the controls on the MasterPage in the Page_Load event handler (shown below).
protected void Page_Load(object sender, EventArgs e)
{
breadCrumb.BreadCrumbs = BreadCrumbs;
header.MenuItems = MenuItems;
footer.Footers = Footers;
head.Controls.Add(CreateCssLink("~/Stylesheets/main.css", "screen"));
head.Controls.Add(CreateJavaScriptLink("~/Scripts/site.js"));
if (Context.Session != null && Session["layout"] == null) Session["layout"] = "single";
if (!ArePreferencesVisible) preferences.Visible = false;
}
I want to be clear here... there are no errors in this code. There are correctly named elements in the MasterPage that correspond to those in this code. It has always worked as expected up until today and I have not changed any code since it was last working. I now get a NullReferenceException on the first line because the breadCrumb element is null. In fact, all the elements from the page that are referenced here are null.
Normally the page elements have been initialised by the time the Page_Load event is raised. What can have caused this to stop happening?
I have double checked that the MasterPage and its code behind file are still connected and they are. I also tried moving this code to the Page_LoadComplete event handler, but the controls had still not been initialised, even at that stage. I shouldn't really have to change the code because it worked just fine before.
I also commented out this code and the website ran, albeit without any styles. Interestingly, when I returned the original code to the event handler and refreshed the page, it actually worked again just as it used to. I loaded a number of different pages successfully and I thought it had fixed itself, so I restarted the application and then got the same error again. No amount of cleaning, building, changing solution configuration or restarting the application and Visual Studio make any difference.
I'm not sure if the app_offline.htm is a red herring, but I've never seen that before either so it might be connected somehow. From what I read, it seems that just removing it causes the server to restart the application domain automatically, so I can't see the connection.
I really hope someone has come across this bizarre situation before because I'm all out of ideas and I can't run my website until this is fixed.
Ok, so I finally tracked down the problem. I had an earlier backup of the website from a few days ago, so I loaded that up and it worked, albeit missing the last few days' work. I copied the latest project code into the Visual Studio > Projects folder leaving the old code in the Visual Studio > Website folder. I loaded the solution and it ran fine again.
I basically compared the Website files, updating each one in turn and periodically running the application. Eventually, the application stopped working. The last file that I had updated was a MasterPage file that extended the MasterPage that had the problem.
What I had done was comment out an empty Page_Load event handler in the MasterPage. I don't understand why that would cause this problem, so any comments explaining that would be helpful and appreciated.
This MasterPage is only used on the home page and a few others, so that explains why I didn't come across the problem the night that I changed it. (I hadn't viewed any pages that used that MasterPage after making the change). I wish I had because it would have been much easier to track down then, but such is life.
So I replaced all of my latest code, added the empty Page_Load event handler in the MasterPage again and finally, everything is working again.

ASP.NET XML Parsing Error: no element found Line Number 1, Column 1 Error

Hey I found a weird temperamental page which randomly gives me the following error
XML Parsing Error: no element found
Location: http://kj2011/site_2011/nonprofit-database/overview.aspx
Line Number 1, Column 1:
This page was fine for like 2 weeks but as of yesterday I randomly get the above error. I was to delete the pages and recreate the error is gone but would come back again few hours later. I have some other templates
i.e http://kj2011/site_2011/nonprofit-database/financial.aspx
Which has the same Master File and User Controls but never gets the error just the overview.aspx page.
Any Ideas ?
That sounds like the Firefox error page that's returned when FF expects HTML and gets an empty document instead. Try looking at it with Firebug enabled and see what the Net tab says - perhaps you have a good header, but no html.
Usually that kind of thing is not due to an ASP.NET error (since with those you still have a document body for the Yellow Screen of Death page), but is more along the lines of a networking error...
Would it be possible to try looking at it from another computer to see if that's the problem?
To find the issue you are having with this problem.
In your global.asax file add:
void Application_Error(object sender, EventArgs e)
{
Exception objErr = Server.GetLastError().GetBaseException();
string err = "Error caught in Application_Error event" +
"\n \nError Message: " + objErr.Message.ToString()+
"\n \nStack Trace: " + objErr.StackTrace.ToString();
System.Diagnostics.EventLog.WriteEntry("MYApplication", err, System.Diagnostics.EventLogEntryType.Error);
Server.ClearError();
}
You can set a break point here or log this message into an EventLog.
The most likely cause for such problem is security, if the problem occurs! check file security and make sure its accessible by asp.net process. (ASP.NET Required Access Control Lists (ACLs)), also does this occur with local calls on the same server?
Another thing is to check your page and make sure you don't have one or more unclosed tags in your markup.
I just debugged this issue on my website. In my case, the cause was a call to Response.End() . You can recreate the error by dropping Response.End() as the first line of Page_Load.
From MSDN ms524629:
The Response.End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.
In my case, Response.End() was being called before any content was written to the buffer. Also, there was no Content-Type in the response header (see attached Firebug screen grabs). My guess is because of these two factors, Firefox didn't know what to make of it and by default it tried to process it as a an XML file.
In your situation, my guess is the extra View.aspx file caused an exception that was interrupting page rendering cycle.
Just for the future reference, in case people come here from google
According to this thread, there are many different reasons to get this error.
In my case this caused by overriding
override void Render(System.Web.UI.HtmlTextWriter writer)
and I have not called base.Render(writer); at the end of overridden function.
This was an issue with an external DLL, which created a page called view.aspx in the same folder which caused an issue with our overview.aspx. We just renamed the page and the issue went away.
When the rewrite of the url in web.config has a problem - the browser send 404 error. Try to comment all the rules and check again if the 404 error arise.
Just to cover all the possibilities. Today I got the same error, no matter the page I was trying to access, but it was a completelly unrelated issue.
For some reason, Skype loaded before IIS on Windows startup and took control of port 80, instead of the usual 17112. Whenever I tried to access a page Skype returned an empty response.
You can simply shut down Skype and reset IIS, but to make sure it never happens again do the following:
Go to:
Skype > Tools > Options > Advanced > Connection
And uncheck Use port 80 and 443 as alternative for incomming connections
some time This type of error occurs when you have app_offline.html file in your directory.When ASP.Net found a file names app_offline.htm in the root of a web application directory, it shut-down the application, unload the application domain from the server, and stop processing any new incoming requests for that application. ASP.NET also then respond to all requests for dynamic pages in the application by sending back the content of the app_offline.htm file. The default content is an error message.
In my case it was the AjaxControlToolkit.dll that was missing from the bin folder. Adding a breakpoint in the Application_Error method in global.asax as suggested above allowed me to find this out.
I met the same problem, in my case, I lost a ';' in a syntax.
App_Themes folder was missing when I got this.

session variable object gets deleted on postback - ASP.NET

I have made something like the following code:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["loginid"].ToString();
}
protected void delete_click(object sender, EventArgs e)
{
delete("mail1",Session["loginid"]);
}
private int delete(string mailid, string user)
{
System.IO.Directory.Delete(Server.MapPath(#"~\files\" + user + #"\" + mailid), true);
}
When i press the delete button, everything works fine and the folder gets deleted.
but after that when page postbacks again then a
NullRefrenceException is raised at
Label1.Text = Session["loginid"].ToString();
why is it happening...??
When I am not using this Directory.Delete() method everything is working fine and session variables are not set to null.
When I traced my application I found that After Directory.Delete() method Session variables were intact and I was able to use those session variables in the processing after Directory.Delete().
But as soon as the page postbacks all session variables are set to null.
And this problem doesn't appear when i m not using this delete() method.
The folder I m deleting is in my project's folder.
I m running this website using Visual Studio.
Please help.
Just another guess here but maybe it's because your modifying something in your applications directory (a hunch since your using Server.MapPath with the ~). IIS maybe thinks the app has changed and recycles the application and as a result wipes out all sessions.
This is similar to if you modify your web.config file while someone is using the app and it drops all sessions and recycles the app. Are you deleting a directory that may contain information that IIS is using for the application?
You said it only happens when you include that line of code and a session will really only get wiped out consistently (unless you are doing it yourself manually) when the application is recycled by IIS or times out. It is obviously not timing out so the recycle must be what is happening.
Is your 'files' folder in your web application folder? Maybe application restarting itself when you deleting the files. Try to use sessionStateServer. Its keep sessions alive.
Web.config:
<configuration>
<system.web>
<sessionState mode="StateServer"></sessionState>
</system.web>
</configuration>
Deleting a folder in your virtual directory may cause your application to re-start, thus loosing all session data. To prevent this, either delete individual files (not folders) or use the StateServer to maintain your sessions.
Since the page loads correctly before you press the delete button, the problem is presumably with the Session["loginid"].ToString() reference. Do you have any other code that references Session["loginid"]? The code you have shown here won't do anything that removes loginid from the Session.
However, if this application is running on a server cluster and you're using the default session mode of in-process, you may be losing access to your session between HTTP requests because they're handled by different servers. See here for more information.
If I remove the directory.delete()
function from the code then the whole
application is running so fine without
any exception
Ok, seems that we found your problem. Your project does not have the necessary privileges to delete the direcotry (even if the directory is deleted.nevertheless: there are privilege problems)
I guess that you're application is throwing an exception while performing this file operation and a new session begins. I have a similiar situation on one of my projects, but I still haven't figured out how to solve it.
I'm pretty sure you will concur with description if you create the Global.asax and set breakpoints on Application_OnError and Session_OnStart (or however these methods are spelled correctly). You will see that the an error is raised and afterwards a new Session is started.
First, a couple of sanity checks:
Does session work as expected on other pages?
Is your Delete method deleting files in a special ASP.NET folder, like App_Data or App_Code, which may be causing the application to restart?
Here's what I would try to debug this issue, after checking the above:
Set a breakpoint on the delete method and have the session variable in a watch window. See what the value of the session variable is before the call to Directory.Delete is and what it is afterward. Is it at that point when you're losing session, or is not until the next page visit?
Use a tool like Fiddler to examine the cookies exchanged between the browser and web server on postbacks. Check that when the browser first visits a new session cookie is created and stored on the browser. Then, when deleting the folder, see if the web server is sending a new session cookie on the response of that postback. This would indicate that a new session has been created.
Thanks

What would cause a bogus 404 for an IIS-served ASPX page?

I have a fairly simple ASP.NET application, set up as a Web Application Project in Visual Studio. There is one particular aspx file called "invoice.aspx" which IIS refuses to serve. The URL I am using is definitely correct, and other aspx pages from this directory load and execute just fine. But not this ONE page! I've put a break point in Page_Load to make sure there is nothing funny going on, but the break point is never hit. The #Page directive looks fine... File permissions are the same as other files in the directory... no errors during build. What am I missing here? This is baffling me. This is IIS6 on a Windows XP dev box.
Well, I knew I'd find the answer myself if I posted about it... :)
It turned out to be a missing DLL. A dependent object could not be created and so it errored out. Why didn't it just give me a missingly assembly error? Ah, that is a good question! With the following bad code example answer:
public partial class Invoice : System.Web.UI.Page
{
DependentObject SomeObject = new DependentObject();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
}
If the assembly for DependentObject's code is missing... the Invoice object, hence the Page to be served, cannot be initialized... the server can't find it... we have a 404.
I don't consider myself an expert in C#, but I am under the impression the above code is something you should never do. (right?) Not sure why the compiler allows it.
Moving the initial object creation to the Page_Load produces the much more useful missing assembly exception.
public partial class Invoice : System.Web.UI.Page
{
DependentObject SomeObject;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
SomeObject = new DependentObject();
}
}
Thanks guys, appreciate the suggestions.
Sending on lots of data, long querystring or otherwise making a request that the built-in IIS7 urlscan might block? If IIS7 blocks a request, it'll send out a 404 error.
Have you tried renaming the file and trying to access that?
Also, use notepad to copy the entire contents of the file into a new file and save that one.

Resources