ASP.Net Master Page and File path issues

后端 未结 10 1308
余生分开走
余生分开走 2020-11-28 02:33

I\'m trying to add a script reference to jQuery in my master page so that it will work for any page. It currently looks like this



        
相关标签:
10条回答
  • 2020-11-28 02:59

    If this script tag goes directly to the browser, then you unlikely can substitute your site's root there. At least not on the server. So you can:

    1. Deploy site to the root of domain name and use absolute paths (simplest solution).
    2. Insert this link with server control.
    3. Preprocess resulting HTML before sending it to the client (with HttpResponse.Filter).
    0 讨论(0)
  • 2020-11-28 02:59

    You can also use <base> HTML tag:

    <base href="http://www.domain.com"></base>  
    

    and then all the links in header section are relative to base address:

    <script type="text/javascript" src="scripts/jquery.js"></script>
    

    It's often useful when you have multiple publishing destinations, like local dev web server, demo server, etc. You just replace that base URL.

    0 讨论(0)
  • 2020-11-28 03:04

    I do not know whether you guys found the solution to your problem or not. I was facing the same problem and going nuts to figure out why do I get "jQuery is undefined" error on the plugins i use. I tried all the solutions i get from the internet but no luck at all.

    But, suddenly something splash on my mind that may be the script files should be in order. So, I moved the jquery referece to first position and everything start working like charm.

    Remember guys, if you're using any plugins with jquery, make sure you use the folloing order of setting reference to those fiels.

    1. reference to the jquery library
    2. reference to the other subsequent plug-in libraries and so on...

    e.g.:

    1. "script src="js/jquery-1.3.2.min.js" type="text/javascript"...
    2. "script src="js/jqDnR.min.js" type="text/javascript"...
    3. "script src="js/jquery.jqpopup.min.js" type="text/javascript"...
    4. "script src="js/jquery.bgiframe.min.js" type="text/javascript"...

    Always make sure you must put the jquery reference to first and then the subsequent libraries.

    Hope, this solves your problem especially when you use with MasterPages. Its very strange that it works no matter what order you use when you don't use MasterPages but when you do, then it somehow requres the proper order.

    Good luck and happy coding,

    Vincent D'Souza

    0 讨论(0)
  • 2020-11-28 03:08

    Look at How to Run a Root “/”. This should fix all your issues regarding unresolved .js file paths. You basically reconfigure the VS Dev server to run your application as localhost:port/ as opposed to the regular localhost:port/application name/ making name resolution work the same way as it does on IIS.

    0 讨论(0)
提交回复
热议问题