3

I have MVC solution with Web side with general users and Admin side for specific users.

I have a lot of JS and CSS files for both Web and Admin side. As I just want to load a lot of Script bundles only when someone logged in, in Admin panel. Those Admin panel scripts should not be loaded when some user visit my website.

As i am loading all the files at BundlesConfig.cs and want, those admin files also loaded for common user as well. i just want to restrict that kind of page overload head.

I tried creating custom BundlesConfig.cs for admin view but stuck with it. Please any one who can help me to optimize the site.

(still have any confusion with question please comment i will update accordingly)

Thank you

2 Answers 2

1

You can load the scripts and styles based on user role in .cshtml page or _Layout page.

@{
    if (User.IsInRole("Admin"))
    {
        //Update this portion with path of required bundles
        @Scripts.Render("~/bundles/jquery")
    }
    else
    {
        //Update this portion with path of required bundles
        @Scripts.Render("~/bundles/jquery")
        @Scripts.Render("~/bundles/jqueryval")
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

Put your minimum required JS and CSS file in bundles. Remaining should be created with the different bundle.

Please make sure that all CSS and JS required are particular for pages or module, I would say have the admin page only add those bundles on the page, instead of the _layout page.

Use script section

@RenderSection("scripts", required: false)

and add your script in that section on your page

@section scripts{ }

Put your page specific script on page only

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.