Ajax Client-side framework Error When Running HTML code - c#

I have a aspx page that uses ajax modal popup extender. I run the project successfully from Visual Studio, it works correctly with IE and Firefox as default browsers.
Now I took the html code and created an html file and put in the proper location. When I open the html file by double clicking on it, it is saying script error like “ASP.Net Ajax Client-side framework failed to load”. Why is it happening when I create an HTML file and open it; and not happening when I run the aspx page from Visual Studio. How to overcome it? What should be the best method to take care this in deployment to production?
Note: I have not entered any entries in the Web.Config related to Ajax. We are not using any update panel. We have used ToolkitScriptManager in the aspx page.
Note: There is one more message after this – ‘Sys’ is undefined.

Are the path of microsoft AJAX related JS files still valid/pointing to correct folder after you copy HTML to a location?

Related

Dynamic HTML in WPF WebBroswer - conent set by BrowserBehavior.Html, linking to file:/// url - does not behave

I am working on a system that has a WPF WebBrowser that is displaying dynamically generated HTML.
This contains links to files, using file:///servername/filename.ext addresses.
This should have worked in times gone by when this was first developed, but does not seem to behave now.
What I can see:
White click on the generated file in the browser of being an HTML file: File is served from about:blank and in the Internet Zone. Clicking a link does nothing.
What I have done:
I have added about:blank to the Trusted Zone, and have set the security for the Trusted Zone to Low. Clicking a link still does nothing.
Created an HTML file and hosted it on my local IIS. Browse to this file in IE. The file contains a link to a file:/// address. Nothing happens on click.
Added http://127.0.0.1 to the Trusted Zone. The above test still fails.
Changed the generated HTML to be a link to http://www.google.com. This works.
What I think is happening:
The WPF WebBrowser is IE underneath. Did IE have a security update that stopped access to file:/// paths?
What I cannot do due to technical restrictions with deployment:
Have the generated HTML and the files linked to served by a web server so everything is within an http(s) environment.
What I can do:
Update browser settings
Update our code
Update - additional information:
The HTML is being displayed on the WPF by binding to a string that contains the HTML (effectively <html><body>Look! Stuff!<br />Whatever</html>)
file:///foo/whatever.txt exists and I have access to it
That file is generated by a process on a server and the client is generating the link to the file. This is a historic design, I didn't come up with it, I'm just maintaining it. I can't do massive code overhauls.
I cannot install any additional services anywhere
All Browsers have updated to prevent interesting stuff happening on local HTML files. Because you could do interesting stuff in the past it meant interesting exploits could be utilized too.
I've had a recent issue where I created a HTML in code and wanted to display it in CEFSharp (much better than WebBrowser by the way) with a link to CSS and JavaScript Files.
How I fixed it was to run a LocalHost and did this using this code which works really well: An HTTP file server (130 lines of code) in VB.Net
For testing your HTML outside of code you could run this batch file to start your LocalHost:
ECHO OFF
ECHO "Launching Localhost:8080"
py -3 -m http.server
ECHO "Loading HTML.."
start chrome localhost:8000
This batch file assumes you have Python 3+ installed. You can verify this in the Command Prompt with:
python --version
I've solved this by cheating a little.
I've got the VM to write the HTML out to a file, and then pass the file name to the browser in the view. This means that I am displaying the created content from file:////foo.htm, and that is fine for links to file:///server/bar

How to access .cshtml page via .aspx

Yes, this is a newbie question and might be ridiculous, but I'm apparently having tremendous difficulty finding an answer to get up and running.
I've created an ASP.NET Razor (v3) web site using the Visual Studio template. That's fine and I can see everything locally. However, when I try to view the Default.cshtml page on the server I get this error:
Server Error in '/' Application.
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.cshtml' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /4.6.1Razor/Default.cshtml
My server administrator says this: You are not supposed to access a cshtml file directly on a production server, it’s blocked by default. Please access an html, htm, asp or aspx file and use that to get the data from the cshtml.
Okay ... so how exactly do I access a cshtml file via an aspx file? Or can someone point me to a working sample that I can look at?
The default files that Visual Studio created did not include an html, htm, asp, or aspx file so I'm a little confused as to how to start that. Also, the samples that Visual Studio points to are of course broken: http://www.asp.net/aspnet/samples/aspnet-web-pages.
A little help pointing me to the right direction would be appreciated. Thanks.
Maybe the question should be ... What kind of page / file (.asp or .aspx or what) do I need to render a .cshtml file and how do I do that. I've tried a .aspx file with the code: #RenderPage("Default.cshtml") but when I view the file in a browser it just echoes #RenderPage("Default.cshtml") instead of rendering anything.
This answer suggests you need to enable WebPages in the <appSettings> section of web.config:
<add key="webpages:Enabled" value="true" />
If this is not enough, check this question for server software requirements to process WebPages.
For IIS application configuration, have a look at this description.
If that doesn't work. Go to IIS --> MIME Types --> Check if the extension .cshtml exists, if not add it.

JQuery load page on browser and execute Jquery - No Selenium

We have tried using selenium for testing, but it has numerous setbacks, delays and sudden crashes.
Jquery sounds a good alternative, but the challenge is how to jquerify every page load on the browser.
Brandon Martinez here has an example of how to add jquery to the console of chrome to jquerify a page:
var element1 = document.createElement("script");
element1.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js";
element1.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(element1);
we want that code to automatically be available in every browser page without the need to manually click a bookmark link on every page.
If we get around that then we can use C# code to:
Process.Start("chrome", #"target site");
and since jquery is already available for every page it will do the population and submit we want.
How can I automatically include jquery for every page that gets loaded on the browser? Is it possible to do that via a chrome plugin; jquery or C# code!? Is it at all possible?
I've decided to use Fiddler to modify response body before being displayed on the browser. Now I can jquerify all pages comes to the browser. Look at this link for a detailed example.

TinyMCE control not showing in Umbraco (Chrome only)

The TinyMCE control for RichTextEditor properties in the Umbraco back-office do not show in Chrome, but are visible in other browsers. The text editor box is just missing entirely.
The Chrome console shows the error
SyntaxError: Unexpected token <
on the page tinymceCompress.aspx
Looking into the source of this file in Chrome Dev Tools, the HTML output for an ASP.NET error page is being appended to the end of the file. The error is:
Server cannot append header after HTTP headers have been sent.
I have manually read the reponse to the tinymceCompress.aspx in Fiddler for both Chrome (not working) and IE (working), and the reponse is exactly the same. There is no ASP.NET error message appended to the bottom of either response.
The control used to show in all browers, it is only recently that it appears to have broken. To our knowledge, we have not modified the Umbraco install.
This is Umbraco 4.11.9.
If you haven't found the answer yet, try looking in the Tiny MCE javascript files. I recall a while ago running into a file which was in the Umbraco release which had a misplaced SCM merge snippet (looks something like <<<). I think it may have been a similar issue.
EDIT: To add to this, you may be able to do a text search across all the scripts that are loaded and look for something like this:
<<<<<<< HEAD
or
>>>>>>> branch_name (as an example)
I had same issue in upgrading Umbraco v4.5.2 to v4.11.9. If you upgrade it from v4.5.2 to v4.11.10 the issue won't happen in Chrome any more.

SharePoint 2010 Allow Code Blocks for a specific page

I am trying to use C# code in an aspx page within SharePoint 2010. I keep getting the "Code blocks are not allowed" error.
My aspx page located at (server)/SitePages/ajax.aspx: (edited in SharePoint Designer 2010 if it matters)
<%# Page Language="C#" %>
<script runat="server">
Response.Write("Hello world");
</script>
I added the following to web.config at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
Here is the same line that I added to web.config, shown in context:
<SharePoint>
<SafeMode
MaxControls = "200"
CallStack = "false"
DirectFileDependencies ="10"
TotalFileDependencies = "50"
AllowPageLevelTrace = "false"
>
<PageParserPaths>
<PageParserPath VirtualPath="/SitePages/ajax.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>
Why do I still get the "Code blocks" error? Is there another security switch somewhere?
(I know custom web parts are the preferred solution, but I don't think that will suffice here because the return value should be json - this is a page to hit via ajax to get data.)
I suppose, you have to define PageParserPath element in an Web application web.config that is located C:\inetpub\wwwroot\wss\VirtualDirectories[application folder]\web.config.
When you upload an aspx page to a document library (which is what you're doing when you use SharePoint Designer) that aspx page can't have inline code blocks and it can't have a code behind. This is primarily a security mechanism. It prevents any old user from uploading an aspx page with malicious content that will then be executed with full privileges on your server, and also serving content to (potentially) any user.
For an aspx page to execute code it needs to be compiled into a WSP and deployed to the GAC on the server. When you do that you can either use inline code blocks or, better yet, have an aspx page with a code behind. To publish that page to the site you would need to compile the project in visual studio into a WSP, deploy that to the server by logging into the machine with sufficient privileges, and then add and deploy the code. This ensures that non-developers can't upload executable code to your site.
Finally, on a more unrelated note, since you don't actually want to display a page, but just JSON content, you probably shouldn't use an aspx page at all (although you can). You should probably just create an HTTP handler or a web service that writes the appropriate content out.

Categories

Resources