Sounds included in Web Application not Playing in IIS - asp.net

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.

Related

IBM SBT :Using Forum API to create discussion forum

How to add the discussion forum in existing application?
Configured with the my application running in WAS and using java snippets i can able to get connected to the connections and get the response .
But with javascript snippets there is a problem .Unable to configure SBT JS and run javascript snippets.
https://localhost:9443/sbt/WebContent/js/sdk/sbt/connections/ForumService is not found
always 404 error in web console.
please help me out
thanks in advance
You should make sure you have the sbt.web project on your server. It sounds like the ForumsService dojo file isn't found.
Also make sure that your managed-beans.xml file is configured, and set properly to point to your connections server.
Here is a snippet which shows the path invocation for ForumService. You can see many more examples in the GitHub Project and reference the wiki which describes your first JS App http://www-10.lotus.com/ldd/appdevwiki.nsf/xpDocViewer.xsp?lookupName=SDK+docs#action=openDocument&res_title=Adding_the_SDK_to_your_web_application_SDK1.0&content=sdkcontent
require(["sbt/connections/ForumService", "sbt/dom", "sbt/json"],
function(ForumService, dom, json) {
var forumService = new ForumService();
var forumUuid = "%{name=ForumService.forumUuid}";
var promise = forumService.getForum(forumUuid);
promise.then(
function(forum) {
dom.setText("json", json.jsonBeanStringify(forum));
},
function(error) {
dom.setText("json", json.jsonBeanStringify(error));
}
);
}
);

local host site, outputting random text

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

View Engines for Web Matrix Web Pages

Microsoft has a new website editing tool: WebMatrix. WebMatrix uses the new Web Pages engine in which Razor is the view engine; Razor is also the new view engine for MVC3. I am attempting to find out if it is possible to register and use a different view engine in Web Pages (like you can in MVC).
Does anyone know if it is possible to add or replace the view engine in Web Pages? If so has anyone documented this? Examples?
I'm hoping to try this myself a bit later, but for now I'll just share my current thoughts:
In WebPages, Razor works by registering a BuildProvider with the ASP.NET build pipe for .cshtml and .vbhtml.
WebPages, in turn, registers the .cshtml .vbhtml extensions to its handler.
When a webPages page is requested, System.Web.WebPages.WebPageHttpHandler passes the path to the build pipe, where the extensions are matched with the registered Razor Provider, which renders the page and passes back a WebPage object, which handler passes to IIS and is served up.
You'll see all this if you use a reflection tool. Both of these are achieved in the PreApplicationStartCode.Start() of the corresponding assembly.
Razor hooking its build provider:
public static void Start()
{
if (!_startWasCalled)
{
_startWasCalled = true;
BuildProvider.RegisterBuildProvider(".cshtml", typeof(RazorBuildProvider));
BuildProvider.RegisterBuildProvider(".vbhtml", typeof(RazorBuildProvider));
}
}
WebPages hooking the WebPageHandler
public static void Start()
{
if (!_startWasCalled)
{
_startWasCalled = true;
WebPageHttpHandler.RegisterExtension("cshtml");
WebPageHttpHandler.RegisterExtension("vbhtml");
PageParser.EnableLongStringsAsResources = false;
DynamicModuleUtility.RegisterModule(typeof(WebPageHttpModule));
ScopeStorage.CurrentProvider = new AspNetRequestScopeStorageProvider();
}
}
To override we'd need to create and register a separate BuildProvider with the ASP.NET pipe to render our pages. System.Web.WebPages provides a WebPageHttpHandler.RegisterExtension() method which in theory you can hook a different BuildProvider to which will get the WebPage request instead of Razor.
Several blogs mention the RegisterExtension method, but there is also an open connect bug report showing it doesn't work 100%. It may be more appropriate to just override everything and hook our buildprovider to the pipe (not using the method).
Web.config provides a construct to register buildProviders, so I'll prob try that.
<buildProviders>
<add extension=".cshtml" type="CustomStuff.CustomBuildProvider"/>
</buildProviders>
The challenge is that most of the view engines out there use ViewEngines.Register(), a concept that webPages does not appear to have. So we'd have to wrap those view engines in a BuildProvider and/or create a BuildProvider that can successfully invoke IViewEngine
Again, just sharing my thinking. I'll try to register Spark or something later if I find some time.
You can't "register" view engines in Web Pages in the same way as MVC. You just mix and match file types. There's nothing to stop you adding .aspx files to your Web Pages site. Web Pages is much more akin to a Web Site project in VS.

Is there a recommended ASP.NET 2.0 method to serve HTML snippets via XHR to the client?

Here is my desired flow:
A static web page (html) uses XHR calls to an ASP.NET page
The .NET page retrieves information from a remote server using web services
The .NET page returns an HTML "snippet" that is inserted into the static HTML page
I'm getting hung up on how to deal with the HTML snippet generation on the .NET (2.0) page. I've thought about something like this in a generic .ashx page:
public void ProcessRequest (HttpContext context)
{
context.Response.Write("<ul>");
//assume "people" is a list of data coming from the external web service
foreach (string person in people)
{
context.Response.Write("<li>" + person + "</li>");
}
context.Response.Write("</ul>");
}
It just seems a big "ugly". Has anyone done this another - and possibly more efficient/elegant - way? Any help would be appreciated.
Returning html for this task is a bit weird, IMO. In most times I prefer the following way. Open your web service to public or add a wrapper to it and just use it directly from js of your static page. The service should return json (preferable) or xml data. On the client side format (print in html as you want) received data using js in callback to the XHR and inject anywhere you want.
But also I want to cast YAGNI on this task - if it'll be used only several times and in a few pages, use the most fastest way to implement it. But if you are building some RIA application I recommend you to check ExtJS javascript library.
Edit 26/02:
If you can't use ASP.NET MVC but wanna to use some good framework instead of "Response.Write" stuff please check OpenRasta. It's one of my favorite web frameworks. It works fine on .Net 2.0 and it's very flexible and powerful. And also it has a great community.

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