scriptreference named respond no longer works

白昼怎懂夜的黑 提交于 2019-12-23 09:07:41

问题


Using: Visual Studio Express 2013 for Web to write a .NET 4.5.1 site.

Project initially built on the default "Create New Website" template therefore the parts in question were added to my project by the IDE and have not been edited.

This has been a several weeks long project and today I began receiving an error out of the blue in relation to "canned" items added at create time. It has been working without error until now.

The error message is:

Server Error in '/' Application.  

'respond' is not a valid script name.  The name must end in '.js'.

I have debugged this to be directly related to this line in my site.master file:

<asp:ScriptReference Name="respond" />

SEE COMMENT HERE This reference is contained in the section of my master file:

This is part of the much larger group of scriptreferences added by the IDE at create time.

In troubleshooting I have tried adding the .js; add a path attribute to the actual file; and commented out the line entirely.

Adding the extension and/or the path results in a different error:

Server Error in '/' Application.

The assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35' does not contain a Web resource that
has the name 'respond.js'. Make sure that the resource name is spelled correctly.

The only successful troubleshooting has been commenting it out BUT this breaks another key feature: Accessing my links requires the .ASPX extension now as previously I could access my links without specifying the extension on my file... and this is the default way the project was created via the ide, so with this fix in place, none of my links work without editing each and every one to include and extension. NOT IDEAL.

I've tried using the Package Manager to update and nothing has been successful there. I have also verified the respond.js file exists in my scripts folder as do the others like bootstrap.

I have searched here and googled for quite some time but there are so many unrelated results that contain excerpts from the scriptmanager that the results are endless.

I am unsure of the correction needed for this or if other files are required. Rebuilding my site has no effect, I've removed "temp" files per one post I read that said it might work for a different but similar issue.

What is the corrective action for this error?


回答1:


In Site.Master file locate the line:

<asp:ScriptReference Name="respond"/>

and modify to:

<asp:ScriptReference Name="respond" Assembly="System.Web.Extensions" />



回答2:


I ran into this same issue myself and fixed it by doing the following.

Add the following code to the RegisterBundles method of the BundleConfig class:

ScriptManager.ScriptResourceMapping.AddDefinition(
                "respond",
                new ScriptResourceDefinition
                {
                    Path = "~/Scripts/respond.min.js",
                    DebugPath = "~/Scripts/respond.js",
                });



回答3:


I had the same problem, and none of the above worked... Verify your global.asax.cs, the Routeconfig and BundleConfig lines were missing in my case, after adding them, it worked again.

    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }



回答4:


Solution:

  • Compile the project at the production server, instead of precompiling on at development machine.

  • If using VS one click publishing tool, under "Settings", make sure "Precompile during publishing" is unchecked.




回答5:


It seems your bundleConfig isn't starting up.

Try to rebuild and clean the project first. After that, try to look into the file Global.asax.cs and see if there is something wrong.

Or try to get a default Global.asax.cs file and copy it into it.




回答6:


This problem occurred for me when I deployed a template asp.net web forms application generated from Visual Studio (2015 in my case) to Azure app service.

For me, none of the solutions given above worked. I got the errors exactly as described in this question.

Then I chanced upon the following article that shows an example of adding a jquery bundle. Adding Bundling and Minification to Web Forms

Following that example, I removed the template code for AddDefinition for "respond" in RegisterBundles method. Then I added the following and rebuilt and uploaded the application dll.

            bundles.Add(new ScriptBundle("~/bundles/respond").Include(
                    "~/Scripts/respond.min.js"));

Then I added the following to Asp:PlaceHolder in site.master.

        <%: Scripts.Render("~/bundles/respond") %>

Finally, I removed the inclusion of respond in ScriptManager in site.master.




回答7:


I tried the above methods without much success. Then I tried as indicated by another post

<add name="BundleModule" type="System.Web.Optimization.BundleModule" />

in between and in web.config

works like a charm. Graham https://forums.asp.net/t/1857743.aspx?Bundling+not+working+when+deployed+to+web+host+works+fine+locally



来源:https://stackoverflow.com/questions/22884640/scriptreference-named-respond-no-longer-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!