VS 2017 Browser Link Not Working with Static HTML - asp.net

In an ASP.NET 4.6 project I have followed the instructions for enabling Browser Link against a static HTML file (used to bootstrap angular) by entering the following in the proper place in web.config.
<add name="Browser Link for HTML" path="*.html" verb="*"
type="System.Web.StaticFileHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
resourceType="File" preCondition="integratedMode" />
This is a very simple web.config and I am fairly certain it is not an issue of the handler not being added properly as described here.
However when looking at the html source in the browser, it does not contain the script tags for Browser Link described in this article.
I was under the impression that if there was a problem while loading handlers, the application would fail to load.Is there anyway to troubleshoot handlers being loaded in ASP.NET?

I am developing an Angular module for a CMS, so I was not including the <body> tag in my index.html.
It turns out, the <body> tag must be present. I am guessing the handler is using XPATH to insert the Browser Link script tags.

Related

How to add another file extension to Razor ViewEngine, e.g. *.html [duplicate]

I manage a large asp.net site which has previously been converted from static html site to asp.net.
For several reasons (mainly SEO) we decided not to rename all the files to .aspx back when we originally converted the site. This was very easy to do by simply adding the buildProvider and httpHandler to the web.config.
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
<httpHandlers>
<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
Now I am upgrading the site to use Asp.net WebPages with Razor cshtml files. I can rename all the files if necessary, and use url rewriting to make the urls stay the same, however it would be much easier if I could just configure the web.config to tell it to parse .html files as if they were .cshtml.
I have searched around quite a bit, and could not find anything equivalent to the PageHandlerFactory for razor pages. It appears as though it is just an internal mechanism in the .net 4.0 ISAPI handler.
The site is currently running on Windows 2003 server and IIS 6. We will be upgrading to 2008/IIS 7.5 in the near future, but I'd prefer not to wait for that.
Is there any way to get the .html files to be parsed by razor as if they were .cshtml files?
Thank you to SLaks for pointing me in the right direction, but it still took a few hours of digging in the MVC source to figure out the solution.
1 - Need to put RazorBuildProvider in web.config
<buildProviders>
<add extension=".html" type="System.Web.WebPages.Razor.RazorBuildProvider"/>
</buildProviders>
And add System.Web.WebPages.Razor to assemblies if it isn't already there.
<assemblies>
[...]
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
2 - Add 2 lines in global.asax Application_Start() method
// Requires reference to System.Web.WebPages.Razor
System.Web.Razor.RazorCodeLanguage.Languages.Add(
"html", new CSharpRazorCodeLanguage());
WebPageHttpHandler.RegisterExtension("html");
Call WebPageHttpHandler.RegisterExtension.
You may also need to register a custom WebPageRazorHostFactory to tell the Razor engine what to do with the file; I'm not sure.
As this actually been resolved for use with VS2012 / .net 4.5.
As using the examples above in a C#5 project I get no luck :(

Intellisense on .LESS files

I'm introducing LESS into an existing ASP.NET web forms application. In order to get intellisense to work, I decided to set up the LessCssHttpHandler to intercept requests for files ending in .less.css. That way, Visual Studio still thinks we're dealing with a CSS file. I did this by adding the following line to my web.config file:
<add type="dotless.Core.LessCssHttpHandler, dotless.Core"
validate="false" path="*.less.css" verb="*" />
In order to get this to work, I had to tweak my IIS settings so that .css files get handled by the ASP.NET framework. Unfortunately, by doing so, now my existing .css files (which aren't handled by the dotless HTTP handler since they don't end in .less.css) aren't returning any content. This makes sense since the ASP.NET framework doesn't really know what to do when it sees a file with that extension.
Is there some sort of base HTTP handler I can set up in addition to the one I have above to handle normal .cssfiles? Something like:
<add verb="*" path="*.css" type="insert some base HTTP handler here that will simply return the contents of the file" />
Looks like the StaticFileHandler is what I was looking for. This is how we ended up adding it to our httpHandlers node in web.config:
<add verb="*" path="*.less.css" validate="false" type="dotless.Core.LessCssHttpHandler, dotless.Core, Version=1.1.0.7, Culture=neutral, PublicKeyToken=96B446C9E63EAE34, processorArchitecture=MSIL" />
<add verb="*" path="*.css" type="System.Web.StaticFileHandler" />
We use Chirpy for our LESS support (as well as our google closure compiler support). It allows you to configure file extensions for LESS, such as .less.css, and then you can have Intellisense support.
It doesn't do translation at runtime but rather at design time within visual studio. When you edit and save the LESS file, Chirpy kicks in and processes the LESS file which generates the css file. This way we avoid having to hand off css file serving to ASP.NET.
I tend to use the console compiler and rename the less file to .css
The httphandler is usually only for people who need parameters in their CSS.

Can I serve .html files using Razor as if they were .cshtml files without changing the extension of all my pages?

I manage a large asp.net site which has previously been converted from static html site to asp.net.
For several reasons (mainly SEO) we decided not to rename all the files to .aspx back when we originally converted the site. This was very easy to do by simply adding the buildProvider and httpHandler to the web.config.
<buildProviders>
<add extension=".html" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
<httpHandlers>
<add path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory"/>
</httpHandlers>
Now I am upgrading the site to use Asp.net WebPages with Razor cshtml files. I can rename all the files if necessary, and use url rewriting to make the urls stay the same, however it would be much easier if I could just configure the web.config to tell it to parse .html files as if they were .cshtml.
I have searched around quite a bit, and could not find anything equivalent to the PageHandlerFactory for razor pages. It appears as though it is just an internal mechanism in the .net 4.0 ISAPI handler.
The site is currently running on Windows 2003 server and IIS 6. We will be upgrading to 2008/IIS 7.5 in the near future, but I'd prefer not to wait for that.
Is there any way to get the .html files to be parsed by razor as if they were .cshtml files?
Thank you to SLaks for pointing me in the right direction, but it still took a few hours of digging in the MVC source to figure out the solution.
1 - Need to put RazorBuildProvider in web.config
<buildProviders>
<add extension=".html" type="System.Web.WebPages.Razor.RazorBuildProvider"/>
</buildProviders>
And add System.Web.WebPages.Razor to assemblies if it isn't already there.
<assemblies>
[...]
<add assembly="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
2 - Add 2 lines in global.asax Application_Start() method
// Requires reference to System.Web.WebPages.Razor
System.Web.Razor.RazorCodeLanguage.Languages.Add(
"html", new CSharpRazorCodeLanguage());
WebPageHttpHandler.RegisterExtension("html");
Call WebPageHttpHandler.RegisterExtension.
You may also need to register a custom WebPageRazorHostFactory to tell the Razor engine what to do with the file; I'm not sure.
As this actually been resolved for use with VS2012 / .net 4.5.
As using the examples above in a C#5 project I get no luck :(

Ajax client-side framework failed to load Asp.Net 4.0

I got a complicated problem with ASP.Net 4.0 Ajax....I started a website with Visual Studio 2010 on my machine,and added some update panels they used to work fine,but suddenly i got that series of errors when i run my website
Microsoft JScript runtime error: ASP.NET Ajax client-side framework failed to load.
Microsoft JScript runtime error: 'Sys' is undefined
The strange things is that i made a website on the same machine with VS 2010 and the update panels there work perfectly.i took its web.config to my new website and changed just the connection..and i got the same error
I tried to search for a solution but i failed to find any real solution.Can anyone help?
Here is the answer by zhughes from this thread on asp.net forum.
The Reason : the path of the javascript generated by the scriptmanager changes when the URL Routing module is used.
The Solution : Tell the routing API to not route the files with "axd" extension (the files generated by the scriptmanager)
Add this rule to the method where you register the routing rules in Global.asax
routes.Ignore("{resource}.axd/{*pathInfo}");
in addition you should have this section in web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
if you using URL rewrite module, then in each rewrite rule add
<add input="{URL}" pattern="\.axd$" negate="true"/>
under conditions tag, like this:
<rule name="HomeRewrite" stopProcessing="true">
<match url="^home$"/>
<conditions>
<add input="{URL}" pattern="\.axd$" negate="true"/>
</conditions>
<action type="Rewrite" url="/home.aspx"/>
</rule>
I have found that this is a possibly a caching/compression issue and by putting in the following into Web.Config, resolves the issue.
<system.web.extensions>
<scripting>
<scriptResourceHandler enableCaching="false" enableCompression="false" />
</scripting>
</system.web.extensions>
I was having the same problem. I installed VS 2010 SP1 and the problem went away.
I had the same problem and I solved it by run the command aspnet_regiis -i on the folder of the Framework 4.0 (on which my application ran). It was a problem on the Handler Mapping of IIS: this operation fix the problem for me.
See also this post.
Hope this could be helpful.
It may be simply missing part in your web.config like the <Handlers> of <httpHandlers>, my advice is if you have old copy of your web config try it out.
Microsoft JScript runtime error: ASP.NET Ajax client-side framework failed to load.
Add reference like this..
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.Services.Client, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
This is a common error that happens when you try to call framework javascript function before page have even loaded them.
So ether run your code when dom is ready (eg pageload), ether place your code after the scriptmanager tag, or check to place it after the javascript load from scriptmanager.
I had this problem and sought an answer from the almighty Google, tried various suggestions including the ones above but had no luck. Gave up and moved on to other work, came back a few days later and the problem had disappeared.
I resumed work, made some code changes and published my website and the problem reappeared. Went back to the Google and came across someone who had the problem while using the 3.5 framework. In that case s/he was able to resolve the problem by going to the 'Add/Remove Programs' control panel and selecting the repair option.
I did likewise, repairing the 'MS .NET Framework 4 Client Profile' and 'MS .NET Framework 4 Extended'. That fixed the problem for me.
Hope that solves it for someone else.
in my case, it's IISExpress, switch back to the cassini dev server fix my headache.
I had this problem as well dealing with a master page and in my case it was a "Base" meta setting that was messing me up. I do recall reading another article/blog somewhere where they mentioned an issue with ajax validation across different domains causing this type of error.
So in my case, I had a <base...> reference setting the default url for the site but my dev was obviously a different url...thus conflict and the "ASP.NET Ajax client-side framework failed to load." error.
Removed the base and voila...error gone.
HTH
Dave
If .Net Framework 4.0 client Profile is not available in your machine , so repair .net Frame work 4.0 or re install .
go to Project Property and select target framework 3.5.
In my case it was the UrlScan tool by Microsoft that was rejecting some URL's requested by Ajax. Disabling it solved the problem.

ASP.NET MVC AJAX Sys is undefined error

I am getting a "Microsoft JScript runtime error: 'Sys' is undefined" error on one of my pages in an MVC application when I attempt an AJAX call. The AJAX call is made from a partial view which is embedded in more than one page. It works fine on all of the pages except one. I have read posts pointing to the web.config file settings and .axd mappings as possible solutions, but the application is configured correctly in the web.config, and the .axd mappings are also correct in IIS. Plus it works fine on all of the pages that use this partial view except one. It is acting like the AJAX libraries are not loading for this one page.
The references to the script files are in the shared site.master file. All of the pages, including the one that doesn't work, reference the same masterpage.
Any ideas? I have been working on this one for two days now. Thanks.
EDIT: As Sam pointed out below, it would seem like the AJAX call is firing before the AJAX libraries have a chance to load. But, the AJAX call is triggered by a submit button long after the page has rendered, so the AJAX libraries have had plenty of time to load - sorry for not giving enough information the first time.
In web.config add the following line of code under appsettings tag:
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
Just in case... use the following to avoid path issues
<script src="<%= Url.Content("~/Scripts/MicrosoftAjax.debug.js") %>"
type="text/javascript"></script>
<script src="<%= Url.Content("~/Scripts/MicrosoftMvcAjax.debug.js") %>"
type="text/javascript"></script>
Source: http://msdn.microsoft.com/en-us/library/dd381533.aspx
Thanks,
Arty
Load the page in Firefox, then use Firebug to inspect the page - you will be able to see all the individual scripts that have been loaded, plus all the network requests that were issued, and whether they succeeded or not. This is better than trying to troubleshoot from the server perspective.
If you are using IE8, you can use the Developer Tools window, but I think Firebug is better - both tools support JavaScript debugging though.
The most likely problem is that you are running script in your partial view before the scripts it is dependent on have had a chance to load - make sure that any script calls you have inside your partial view will only run once the page has loaded, and not immediately during loading.
All the above cases are ok.But sometimes developer forget to add javascript files for ajax .So please check that also.
Basically you might be missing: MicrosoftMvcAjax., MicrosoftMvcValidation.debug and MicrosoftMvcValidation JS file references.
Do the below steps:
PM> Install-Package MicrosoftAjax
PM> Install-Package MicrosoftMvcAjax.Mvc5
Include them in bundleconfig like below:
bundles.Add(new ScriptBundle("~/bundles/mvcFoolProof")
.Include("~/Scripts/MicrosoftAjax*",
"~/Scripts/MicrosoftMvcAjax*",
"~/Scripts/MicrosoftMvcValidation*",
"~/Scripts/mvcfoolproof*",
"~/Scripts/MvcFoolproofJQueryValidation*",
"~/Scripts/MvcFoolproofValidation*"));
Now it should work without any errors.
Add to web.cofig in section:
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
Regarding your response to Sam, one thing I've noticed in a lot of MVC apps is that people don't know how to deal with the ambiguity of relative paths and the application/runtime. For example, the URL rewriting pretty much guarantees that a particular page can appear at different depths than you anticipated, so ../../images will point somewhere else depending on whether you're looking at /products/widget or /products/widget/12345, even though the view might be the same. As Arty pointed out, the best way to deal with this is to let the engine do the work for you by using a URL utility and application-relative paths that will be fixed up by the application regardless of the context.
I have also found that using the following works with ASP.NET MVC2.
Instead of using MicrosoftMvcAjax.js, you use MicrosoftMvcValidation.js
Hope this helps someone.

Resources