Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Explanation.

I have applied anonymous access to entire website. My Javascript working fine while users login. But not woking while anonymous users visits the site.

I need to execute masterpage javascript while anonymous user visits the site.

Thanks...

share|improve this question
1  
Where is the JavaScript stored? 14/15 hive? Style library? Embedded in the master? –  webdes03 Apr 10 '13 at 11:26
    
My javascript Embedded in master page –  Hitesh Chandegara Apr 10 '13 at 11:45
add comment

3 Answers

up vote 2 down vote accepted

I presume that you have your JavaScript files stored in the hive files? if so it would be under the layouts folder! and also that you have set annoymous access to the whole site means that by default annoymous users dont have access to the layouts folder! its a saftey feature!

hence why logged in users have access and can use the JS file whereas annonymous users dont have privlages ;) so it doesnt work!

This means that you need impersonation! but that requires cutomisation of webservices and other things like webparts ect where you can put in code to impersonate ;)

my personal sugestion is to create a feature that adds the JS to the page rather than it being in the masterpage! You can then set impersonation for the reference for it to work for annoymous users ;), have the feature scoped to site level!

bingo! you have JS files in _Layouts folder enabled for the annoymous users!

for referencing the JS in feature:

Include JavaScript in a feature

or

what type of master page are you using? you should look into publishing masterpage that should contain the correct access for annoymous users using JS

EDIT

So you now have your reference in the master page to the JS files in 12/14 hive within the layouts folder!

to grant access you need to ammend your web.config file like so:

<location path="_layouts/1033/mycustomfolder/thisIsMyJavaScriptFile.JS">
    <system.web>
      <authorization>
        <allow users="*" />
      </authorization>
    </system.web>
  </location>

the above code is giving access to all users (including anonymous users) to the JS file. So you can keep the current masterpage ;)

share|improve this answer
    
thanks buddy... let me tried your suggestion. –  Hitesh Chandegara Apr 10 '13 at 11:50
    
what type of master page you using? you should be using publishing masterpage for annoymous sites –  ali Sharepoint Apr 10 '13 at 11:54
    
i using V4.master page which resides _catalogs/masterpage location.. i need publishing masterpage for anonymous site.. right ? –  Hitesh Chandegara Apr 10 '13 at 12:10
    
just ammended my answer for you! should be a simpler solution for you! –  ali Sharepoint Apr 10 '13 at 13:24
    
Thanks buddy !!! –  Hitesh Chandegara Apr 10 '13 at 13:38
show 1 more comment

If you save your script in an external js file, and store it under LAYOUTS on the 14 hive, you shouldn't have problems to access the files by anonymous users.

The path to the folder in your server should be something like:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033

Then on your v4 master call the script like in the line bellow:

<script type="text/javascript" src="/_layouts/1033/bootstrap-alert.js"></script>

After editing the master with SharePoint designer don't forget to check-in the file, otherwise only you will be able to see the changes.

share|improve this answer
add comment

If your script is on the master page check it in and publish the major version

share|improve this answer
    
This is what solved it for me. I set the option where I didn't have to check out files to edit them (I'm the only editor), so I figured I didn't have to check them in. But I DID have to publish a major version. –  BGM Jul 18 '13 at 20:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.