Category Archives: BundleConfig

[RESOLVED] Oauth.config not in templates

When i start a new web forms project the OAuth.conig file is not in the app_start folder, and only thing that is in there is BundleConfig.cs.

I've got .net 4.5 installed, is there some type of update that i need to apply to get access to the auth examples?

[RESOLVED] Javascript Runtime Error "Unable to set value of the property 'scriptsFailed': object is null or undefined" from dynamic user control

Hi Experts,

would like ask some help for my issue. I have a user control which is being loaded using "LoadControl" to a placeholder. this is done on server-side from a button click.

I have a user control that implements IScriptConttrol and is accompanied by javascript file which contains class prototype.

The user control then registers on the parent page's scriptmanager.RegisterScriptControl the script

protected override void OnPreRender(EventArgs e)
        {
            scriptManager = ScriptManager.GetCurrent(Page);
            if (scriptManager == null)
            {
                throw new HttpException("A ScriptManager control must exist on the page.");
            }


            foreach (string attr in this.Attributes.Keys)
            {
                mainContainer.Attributes.Add(attr, this.Attributes[attr]);
            }

            scriptManager.RegisterScriptControl(this);

            // we overwrite the panel-ID with the control-ID -> we are able to adress it easily in an ASPX
            mainContainer.ID = this.ID;
            mainContainer.ClientIDMode = ClientIDMode.AutoID;

            base.OnPreRender(e);

        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);
            scriptManager.RegisterScriptDescriptors(this);

        }
        #region [ IScriptControl members ]
        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
        {
            yield return new ScriptControlDescriptor("Namespace.Designer", mainContainer.ClientID); ;
        }

        IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
        {
            return BundleConfig.getScriptReferences("~/bundles/xml", "~/bundles/scripts/designer");

        }
        #endregion

If I include the user control in the Markup as <tag:Designer runat="server" id="designerControl"/>
I don't have a problem and everything works fine. 

But removing it and loading the user control dynamically at code-behind raises the javascript error "Unable to set value of the property 'scriptsFailed': object is null or undefined".

If I try to comment out the 

scriptManager.RegisterScriptControl(this);

the page works fine. but I need the javascript class, so just to eliminate factors - I did this.

Is it conclusive that the approach above do not work for dynamic user controls? is there a workaround or am I missing something?

Need all any help i can get. I've been trying to find articles about the issue and how to resolve for half day already but no luck.

Thanks in advance.

-Mailman

script manager control should be placed before user control in aspx page, check if you have the correct sequence of controls.

[RESOLVED] App_Start folder

I created an empty Web Project added an App_Start folder and placed in a BundleConfig.cs file inside it, if I put a break point; this code is never executed?

So is App_Start folder really starting when the app starts(BTW there is no global.asax file in the project) its a naked web project

I had to go by creating an _AppStart.cshtml file which actually gets called when I launch my web site (strange)

App_Start is th location to place the configuration class files.Yes, you can place your _AppStart.cshtml in that folder , and check now!

mettlus

I created an empty Web Project added an App_Start folder and placed in a BundleConfig.cs file inside it, if I put a break point;

It's part of web optimization (minification and bundling) framework. Read this..http://www.asp.net/mvc/tutorials/mvc-4/bundling-and-minification

[RESOLVED] How to redirect to another project's localhsot in ASP.NET

I have the following part of the code in one of my ASP.NET Web Forms application. The point is that in my solution, I have another ASP.NET Web Forms application, but of course with different `localhost port`. The thing is that, I want to redirect actions taken by the code below, to my first projects `localhost`. Meaning, it should read the image thumbs from my first projects `localhost`, when someone clicks on the name of the book, it should redirect it to my first `localhost`, where there is more information about book, and most importantly, if someone clicks Add to Cart, I want it to be placed in my first projects cart. So, I just want to redirect those actions to my first project's `localhost`. Here is the `localhost` of my first project: `http://localhost:53417/`

I guess I need to somehow change the parts regarding `href` or change something in `MapPageRoute`, but don't know how. If someone can give me some code help, I would be glad. Please note that below code is inside a ListView.

<ItemTemplate>
                                    <td id="Td2" runat="server">
                                        <table>
                                            <tr>
                                                <td>&nbsp;</td>
                                                <td>
                                                    <a href="<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">
                                                        <image src='/Catalog/Images/Thumbs/<%#:Item.ImagePath%>'
                                                            width="75" height="100" border="1"/>
                                                    </a>
                                                </td>
                                                <td>
                                                    <a href="<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">
                                                        <%#:Item.BookName%>
                                                    </a>
                                                    <br />
                                                    <span class="BookPrice">
                                                        <b>Price: </b><%#:String.Format("{0:c}", Item.UnitPrice)%>
                                                    </span>
                                                    <br />
                                                    <a href="/AddToCart.aspx?bookID=<%#:Item.BookID %>">
                                                    <span class="BookListItem">
                                                        <b>Add To Cart<b>
                                                    </span>
                                                </td>
                                            </tr>
                                        </table>
                                    </td>
                                </ItemTemplate>

Global.asax.cs:

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

        RegisterRoutes(RouteTable.Routes);
    }

    void RegisterRoutes(RouteCollection routes)
    {
        routes.MapPageRoute(
            "HomeRoute",
            "Home",
            "~/Default.aspx"
        );
        routes.MapPageRoute(
            "AboutRoute",
            "About",
            "~/About.aspx"
        );
        routes.MapPageRoute(
            "ContactRoute",
            "Contact",
            "~/Contact.aspx"
        );
        routes.MapPageRoute(
            "BookByNameRoute",
            "Book/{bookName}",
            "~/Catalog.aspx"
        );
    }


GetRouteUrl returns URL like /Book/SomeName. So, to make it as http://localhost/Book/SomeName add "http://localhost"

<a href="http://localhost<%#: GetRouteUrl("BookByNameRoute", new {bookName = Item.BookName}) %>">

To redirect AddToCart set correct url

<a href="http://localhost/AddToCart.aspx?bookID=<%#:Item.BookID %>">

I hope you understand that this will work only on the test server and need to be modified when going on production.

Thanks, it worked just fine.

[RESOLVED] Bundling and Minification works in debug mode but in release mode it is not working very urgent

Hi All.

This is an urgent request. I have a unique scenario. I have done bundling and minifcation done. But I see that it is working in the debug mode but not in release mode(please note debug mode is working & release mode is not working). I have ensured that files with .min extensions are not bundled. Also I see that the bundles are actually rendered in the browser (using F12 debugger), but when a call to the method in JS file are made it is throwing an error.

I also ensured that the bundle order is set. I use the below code to set the bundle order

public class AsIsBundleOrderer : IBundleOrderer

    {

       public virtual IEnumerable<FileInfo> OrderFiles(BundleContext context, IEnumerable<FileInfo> files)

        {

       return files;

        }

    }

Enev after all these things the error exist.

My only doubt is the can there be any issue in calling the minified script from ASPX page. Is it changing some function names or any other JavaScript object names.

If this is case how to avoid minification and just use bundeling alone.

Thanks and regards

The difference is this. Let's say you have both jquery-1.9.1.js and jquery-1.9.1.min.js in your scripts folder.

Debug modewill use jquery-1.9.1.js as the source script, and no it won't be minified or bundled, as the whole bundling/minification is disabled in debug mode (though you can override this).

Release modewill use jquery-1.9.1.min.js AND bundle it with other scripts for that bundle. If you only have the one file, jquery-1.9.1.js

, Release mode will use it and minify and bundle it. Debug mode will NOT use .min files. So if you use a wildcard to include all files for a scripts directory, your .min files will not be included.

Debug mode, if you look at the rendered HTML, will reference all script files in the bundle individually. In Release mode, there will only be one script reference (with a querystring for versioning) per bundle.

When using Bundling and Minification in debug mode (when <compilation debug="true" /> is set in your web.config ), undling/minification is disabled.

You can override this and force bundling and minification by adding

BundleTable.EnableOptimizations = true;

. This will make it act like it will in your production environment, where everything is bundled and minified, and the script reference includes that versioning parameter (like you gave) that will force the browser to reload your scripts when anything changes:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        //all your bundle code
        BundleTable.EnableOptimizations = true;
    }
}

Please reference. Hope that's helpful.

 

Hi Chunyan Yu,

Thanks for your reply. I have tried this and have replicated the error in local machine also. In unbundled state the scripts are working fine where in bundled state the script is not working. I'm using Jquery 1.9.1 and all my scripts are depeneded on that. I have  two bundled created

1) Jqeury, Jquery -UI

2) Application specific script bundles

The Jquery and Jquery UI are included in master page where as the application specific bundles are all put in child pages that inherit from master page.

Even after this I find that the application specific pages are not working. Using f12 developer tools I'm able to see both the Jquery bundle and Application specific bundle getting downloaded. But still I get an error saying Jqeury ($) is invalid.

But the same thing works in google chrome. Are there any suggestions. It is pretty urgent and I'm stuck

Thanks and regards

 

Hi All,

 

I have found a solution for the same. It appaears like the .min.js version of Jquery are having some proble. When I did some googling I see that there was some issue @soureMapURL issue in Min.JS. But that was also correct in 1.9.1.min.js. Since I could not find the exact cause. I just removed the min.js and allowed the JsMinifier itself to the jb of minification and that worked like magic.

 

Thanks and regards

Venkatesh