Saturday, 31 March 2012

How to restrict Form pages from anonymous users

Recently i faced the issue with view all site content page from anonymous users and site users(those who have permission for add,edit and customize the pages and lists).
Using with below code hided SiteActions drop down form all users except who can 'MangaePermissions'.
Removing SiteActions from ribbon:
<!-- site Actions--><SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" PermissionsString="ManagePermissions">site Actions control here</SharePoint:SPSecurityTrimmedControl>

Every thing is fine but sometimes most of organizations when dealing with public facing anonymous access sites. So you need to restrict /_layouts/viewlsts.aspx page from anonymous users because this page is displaying for anonymous users.  
So Anonymous users don’t have access to the Forms page (e.g. http://ServerName/Pages/Forms/AllItems.aspx).

The following steps will help you to restrict it. This feature is known as lock down feature which is by default enabled for publishing sites.
Firstly check with ViewFormPagesLockDown feature in your site if it is enabled or not.
You can check ViewFormPagesLockDown the feature from below command.

Using with Powershell script :
get-spfeature -site <URL>

Look at all the features listed and see if ViewFormPagesLockdown is enabled. If you see it listed then it is enabled, otherwise ViewFormPagesLockdown is disabled.
The lockdown feature can be enabled or disabled. To enable it first run the following command.
$lockdown = get-spfeature viewformpageslockdown

Now execute the following command to enable it.
enable-spfeature $lockdown -url <SiteCollectionURL>

Using with STSADM:
Open cmd prompt in Administrator mode
and go for C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN
and type
stsadm.exe –o activatefeature –url <site collection url> -filename ViewFormPagesLockdown

 Even when lockdown mode is enabled, anonymous users can still access certain application URLs, such as pages in the _layouts directory and Web services that are exposed in the _vti_bin directory. So, to increase security, you should enable lockdown mode and also modify the Web.config file. Click on this link to increase security

Saturday, 10 March 2012

Best ways to add a new line in to C# strings in Visual Webpart

There are a couple options to add new line in a strin using with C# programming language,

These C# programs use the Environment.NewLine property. NewLine equals \r\n.
String = st;
st="your account has been created successfully" + "<br />" + "Temporary pasword will be sent your email";
st=st.Replace("<br />", System.Environment.NewLine);

Using with '\r\n'  :
string=st;
st="your account has been created successfully" + "\r\n" + "Temporary pasword will be sent your email";

How to hide or set permission to show the customized Yellow status bar

Last week i have customized the wiki pages using with SharePoint Designer 2010.

One of the side effect i have observed one yellow status bar, it shows up on the customized pages in the browser, "The current page has been customized from its template. Revert to Template". If end users clicks on the "Revert to Template", it would reset the page to the site definition.


After much research about this i noticed one DIV tag in masterpage. ie  
<div id="s4-statusbarcontainer">
    <div id="pageStatusBar" class="s4-status-s1">
    </div>
</div>

set the DIV visibility status as 'none' so the div will not visible. 
<div id="s4-statusbarcontainer" style="display:none">
    <div id="pageStatusBar" class="s4-status-s1">
    </div>
</div>

with above process status bar will not visible to administrators, Contributors,Viewers, or anonymous users. So that even administrators also can not see the status bar and its message.
If you want to show such alerts only administrators and contributors, not to viewers,anonymous users. Then you wiil need to play around with permission attribute.

Just put the above DIV tag in SecurityTrimmedControl with permission status "Manage web"
<SharePoint:SPSecurityTrimmedControl id="SPSecurityTrimmedControl" runat="server" Permissions="ManageWeb">
<div id="s4-statusbarcontainer" style="display:none">

    <div id="pageStatusBar" class="s4-status-s1">
    </div>
</div>
</SharePoint:SPSecurityTrimmedControl>
with above code who can manage the web they can only see the status bar. Anonymous users can not see the status bar just like below screenshot


Monday, 20 February 2012

Top 10 Best SharePoint Sites of 2011

SharePoint is one of the most successful products ever launched by Microsoft. Creating a branded SharePoint site involves understanding both traditional web design techniques as well as topics that are typically reserved for developers. Things like creative design, the experience visitors have navigating your user interface, ease of use etc; these are all important branding considerations. Here are the top 10 best SharePoint sites of 2011. Have a look!


http://microsoftfeed.com/2012/top-10-best-sharepoint-sites-of-2011/

Tuesday, 10 January 2012

SharePoint content database is in suspect mode in SSMS

Sometimes SharePoint site may get internet explorer error.

In my environment i am using SQL Server 2008 R2, SharePoint 2010, Win 7

I have found the error in MSSQL SERVER. Because my SharePoint site application content database is MSSQL Server not with SharePoint. I checked in Sql server here my data base is in suspect mode, So thats why this SQL server not allowing to perform any operations on that database. See here


Database can go in suspect mode for imporper shutdowns of sql server and ....etc. reasons,

To get the exact reason of a database going into suspect mode can be found using the following query.
Run this query:

"DBCC CHECKDB (’YourDBname’) WITH NO_INFOMSGS, ALL_ERRORMSGS"

Output of the above query will give the errors in the database.

To repair the database, run the following queries in Query Analyzer,

EXEC sp_resetstatus ‘yourdbname’;
ALTER DATABASE yourdbname SET EMERGENCY
DBCC checkdb(’yourdbname’)
ALTER DATABASE yourdbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (’yourdbname’, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE yourdbname SET MULTI_USER

I have found this solution from this blog

SharePoint Error message Full descriptive

SharePoint developers and Administrators sometimes will may get the error message as "An unexpected error has occurred"

By default SharePoint 2010 did not return a descriptive error message.
For displaying error message description you need to turn on Error Message.

Here are the steps for turning on the error messages instead of "An unexpected error has occurred"
  1. Open IIS--> and right click on the site and select explorer.
  2. Find web.config filen right click on it and select open with notepad.
  3. Find this line "<SafeMode MaxControls="200" CallStack="false" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="false">"
  4. Change both "CallStack" and "AllowPageLevelTrace" from false to true.
  5. Find the line "<customErrors mode="On" />" and change the mode from On to Off.
Now you will be able to see the error message with complete details.
You can get the error message description from Errors Event ID in Even Viewer.
And you can get all the information about error message in URL Logs in C:\...14\LOGS folder.

Tuesday, 27 December 2011

An unhandled exception occurred in the Silverlight Application

If you get an error "An unhandled exception occurred in the Silverlight Application in SharePoint 2010" when you try to create a document library, list, site or anything in SharePoint 2010.

I got this error in my environment when i created Picrure Library in Team site.
Genrally it could be that security validation has been disabled in Webpart Security Validation(Central Administration--> Web Application--> General Settings).


For detailed explanation please find this link