Tuesday, April 30, 2013

Customizing the Request Access page in SharePoint 2010

This article is Based on below URL :
http://oszakiewski.net/eric/customizing-the-access-request-page-in-sharepoint-2010


Our organization, like many others, handles access requests for all applications through our IT Support desk. Additionally, documentation is required and must be approved by the user’s department manager before the access can be granted. After just recently migrating the entire company’s intranet over to SharePoint 2010, I wanted to allow users to request access, so I made sure the Manage Access Requests was selected by default for all resources. However, within a week of moving it over I’m getting requests for all sorts of things in my inbox every day, even from our kiosk service accounts in the employee break room or at terminals, which are both locked down intentionally. I don’t mind the access requests, but there needs to be a consistent way of handling requests that complies with our internal standards.
I did some research into the Access Request email message that comes from SharePoint, thinking maybe I can modify the timer job, workflow, email content, etc. Nothing. In fact, the very same discussion is held in a TechNet article located here. Bummer, this would have been ideal.
So what’s the next best step? Modify the reqacc.aspx file in C:\program files\common files\microsoft shared\web server extensions\14\template\layouts.
Here’s what the original page looks like:

** WARNING: Make a copy of the original file BEFORE modifying! Making changes to the layouts folder in SharePoint is always at your own risk! If for any reason your changes are unsuccessful, you can always delete that file and place the copied original back in the folder to restore functionality!
That being said, here’s what I did to create a custom Request Access page:
1. Navigate to your layouts folder, typically located at c:\program files\common files\microsoft shared\web server extensions\14\template\layouts
2. Make a copy of the reqacc.aspx file and put it somewhere safe. Make NO changes to this copied file!
3. Open the other reqacc.aspx file (not the copy) in your editor of choice.
4. Near the bottom, locate the following section of code:
<td id="RoleDescription" class="ms-descriptiontext"><br/><SharePoint:EncodedLiteral runat="server" text="<%$Resources:wss,reqacc_entermsg%>" EncodeMethod='HtmlEncodeAllowSimpleTextFormatting'/></td>
< /tr>

This is the section of the page that says “Type your request, and then click Send Request.” Deleting it breaks the page because SharePoint is looking for specific elements in the page, so all I did was hide it by adding the following CSS attribute:
<td id="RoleDescription" style="display:none" class="ms-descriptiontext">
This will override the CSS class settings and hide the element altogether. Do the same thing to the textarea below it, to prevent users from entering in anything:

< td class="ms-descriptiontext">
< textarea name="txtareaMessage" id="txtareaMessage" rows="0" cols="0" class="ms-descriptiontext" runat=Server></textarea>
< /td>

This is the textbox that says “Supply a description of the action you were taking and the URL you were trying to reach.” I hid the entire element by adding the same style attribute like so:
< td class="ms-descriptiontext"
style=”display:none”>
<textarea name="txtareaMessage" id="txtareaMessage" rows="0" cols="0" class="ms-descriptiontext" runat=Server></textarea>
< /td>

5. If you want to enter a custom message or instructions for the user to follow, I put that in place of the input button in the next table row below the textarea, located here:

< td>
< input type="submit" value="<%$Resources:wss,reqacc_sendreq%>" id="btnSendRequest" accesskey="s" runat="Server"/>
< /td>

Here is a sample of what I replaced it with:

< td>
< font size="4pt">To request access, please fill out a User Access Request Form located <a href="internal link to InfoPath form">here</a>. Make sure the resource you need access to is listed in the form, including the URL listed above.</font>
< /td>

Save the file and the changes are immediate. The end result will look something like this:
You could theoretically change this page however you want, but I liked the existing simplistic layout, it got to the point and provided the end user with enough information. Of course, custom application pages can be made and used in SharePoint nearly anywhere. Hope this helps!

Tuesday, April 23, 2013

HTML Formatter

Formats a HTML string/file with your desired indentation level. The formatting rules are not configurable but I think it provides the user with the best possible output.
Note that the formatter will keep spaces and tabs between content tags such as divs and spans as it's considered to be valid content.
*Files bigger than 1 meg will be formatted to a new window.

Good tool for HTML format:

http://www.freeformatter.com/html-formatter.html

Sunday, April 7, 2013

How to transfer logins and the passwords between SQL Servers

http://sqlserver.in/blog/index.php/archive/category/administration/database-migration/

Step-by-Step Guide to Configuring Database Mirroring in SharePoint 2010

I was looking up some material on database mirroring, and I could find a good step-by-step post on setting up such functionality. So here it is!
Read these posts before you begin - you should really understand the concepts if you are to undertake this, especially in a production environment.
http://technet.microsoft.com/en-us/library/dd207314.aspx
http://blogs.technet.com/b/wbaer/archive/2010/05/03/database-mirroring-in-sharepoint-2010.aspx
http://www.sharepointbandit.com/2010/08/configure-database-mirroring-on.html
My SQL instances are based on the SQL Server 2008 R2 Standard SKU, but they we're upgraded from SQL Express 2008 R2, hence the sqlexpress names:
Mcm-server-1\sqlexpress (Primary) & Mcm-server-2\sqlexpress (Mirror)
SQL Service Account: mcm\svc_sql
Database to sync: WSS_Content_ProductionDB
For mirroring to work, the versions of SQL must be the same on both servers.
1. Configure permissions on the mirror server according to the details from the technet article:
  • The Central Administration application pool account should be a member of the dbcreator and securityadmin fixed server roles.
  • All application pool accounts, the default content access accounts, and any accounts required for service applications should have SQL Server logins, although they should not be assigned to SQL Server fixed server or fixed database roles.
  • Members of the Farm Administrators SharePoint group should also have SQL Server logins and should be members of the same SQL Server roles as the Central Administration application pool account.
2. Ensure that no firewall is blocking connectivity between the servers. In particular, you will create a TCP connection over a port, by default 5022.
3. Make sure that the database is in the Full recovery model
clip_image001
4. Perform a FULL backup of the database you are going to mirror:
clip_image002
5. Place the backup to a place where the mirror server can access it. I dropped it on a network share:
clip_image003
6. Restore the database on the mirror SQL Server. Notice how I have referenced the UNC path - SQL's interface here is not the best, you have to type in the location and file name for it to find the backup. See the next point before you proceed.
clip_image004
clip_image005
7. On the restore page you MUST select a RESTORE WITH NORECOVERY under the Options menu. This is required for DB mirroring to work:
clip_image006
8. Assuming your restore was successful, the database will always show as "Restoring…":
clip_image007
At this stage you could proceed with setting up mirroring.
9. Go to the Mirroring settings page on the Primary server's database in the Database Properties section. Go ahead and click Configure Security…
clip_image008
10. Run through the wizard. Select to set up a witness server if the situation requires one. The wizard will ask you to configure the endpoints for communication on all instances. Make sure the port is open over TCP and that you select to encrypt the data.
clip_image009
clip_image010
11. The next screen lets you specify database mirroring service accounts. In my case I left them blank as all SQL instances are running under the same service account. Read this article for more info on service accounts: http://msdn.microsoft.com/en-us/library/ms189434.aspx
clip_image011
12. Continue the wizard and your endpoints will get created:
clip_image012
13. Click close and you will get the next message with some information. Click the Start Mirroring button and hopefully it works (:
clip_image013
14. You should get no errors and your Mirroring page should look similar to mine. (I postponed the configuration of my witness):
clip_image014
15. Your databases will indicate that mirroring is configured:
clip_image015
clip_image016
(ignore the ArchiveDB in the screenshot, I had to set it up twice...)
16. To check if it is all working you could use the "Launch Database Mirroring Monitor" tool:
clip_image017
This will provide you with information, which is near real time. I uploaded a large document on the Primary server in SharePoint and refreshed the tool a few times:
clip_image018
Now it is time to tell SharePoint that we have a failover database set up. SharePoint must know this to change its connection string when the mirrors swap. To do this we must use PowerShell:
$db = get-spdatabase | where {$_.Name -eq "WSS_Content_ProductionDB"}
$db.AddFailoverServiceInstance("MCM-SERVER-2\sqlexpress")
$db.Update()
In Central Administration you will see the setting populated. Read Bill Baer's post on how exactly this setting is used.
clip_image019
As a final test, go back in SQL, go on the mirroring page and click the Failover button. This will ultimately swap the roles of your two databases.
clip_image020
Click it and make sure SharePoint is still working for you! Hope this helps!

Ref: http://www.sharepoint.bg/radi/post/Step-by-Step-Guide-to-Configuring-Database-Mirroring-in-SharePoint-2010.aspx

***********************************************************************

Here is the detailed step by step implementation of Database Mirroring with screen shots. Note that I have shown here is a High Protection Mirroring scenario.
Here we are setting up a synchronous operating mode.
Step 1
Create MirrorDB in the source database (called as Principal database), for which we are going to start mirroring.
mirror1
mirror2
Step 2
Create a backup of the MirrorDB in the source SQL Server (Principal database) & restore it in the destination server with the same name. Make sure to restore the database with NORECOVERY. The destination server MirrorDB is called as Mirror database.
mirror3
mirror4
mirror5
mirror6
mirror7
mirror9
Step 3

As shown in the below screen, right click on the database, select properties & select Mirroring. Select Configure Security to configure mirroring for the required database.
Follow the screen shots as given below.

Note that here I do not have a Witness server, & hence select “NO” for include Witness server option.
mirror10
mirror11
mirror12
mirror13
Step 4
Select the Mirror Server Instance as shown below & click connect. Here we have to specify the destination, i.e. Mirror database server’s credentials to connect.
mirror14
Step 5
Leave service accounts for both Principal & Mirror blank, follow the remaining screen shots.
mirror15
mirror16
mirror17
Step 6
Click on Start Mirroring to start the mirroring from Principal database to Mirror database.
mirror18
Step 7

As you can see in the below screen shot, the status is, the databases are fully Synchronized.
mirror19
Step 8
The MirrorDB in the source server is now marked as Principal, Synchronized.
mirror20

Step 9
The MirrorDB in the destination server is now marked as Mirror, Synchronized (Restoring)
mirror21

Step 10

You can do manual failover as shown below, by selecting Failover option.
mirror22
mirror23b
Step 11

The Principal database is now changed to Mirror & the Mirror is changed to Principal as shown in the below screen shots.
mirror23
mirror24
Mirroring is a simple process & if failed we can easily reset it up, by restoring the latest backup of the source in the destination & reconfigure Mirroring.

Thursday, April 4, 2013

Customize Error Page, Page Not Found and Access Denied in SharePoint 2010

There are many ways to customize these pages for example you can customize by code by creating a feature at web application scope or you can do it by power shell so let’s see the simple way.
First create three pages and place them in this path
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\
Custom_Error.html
Custom_NotFound.html
Custom_AccessDenied.html
Note: if you have multilingual site you need to place these pages in their language folder for example for Arabic
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1025\
Second Open SharePoint 2010 Management Shell with Farm Administrator User
Now For Custom page Not Found runs the following Power Shell:
$webApp = Get-SPWebApplication http://test 
$webApp.FileNotFoundPage = “Custom_NotFound.html” 
$webApp.Update() 
For Custom Error Page, Access Denied page,.. All pages listed in the below image

Run the following Power Shell:

$webApp = Get-SPWebApplication http://test
$webApp.UpdateMappedPage([Microsoft.SharePoint.Administration.SPWebApplication+SPCustomPage]::Error,"/_layouts/1033/Custom_Error.html") 
$webApp.Update() 

Ref: http://salvatoredifaziosharepoint.blogspot.com/2012/03/how-to-customize-sharepoint-2010-error.html

***************************************************************************
**************************************************************************
Part of the reason we want to change the Access Request page is the users get confused when they see “Error”. We want them to “knock on the door of sites” and request access so the email will go to the user-site manager of the site. They see – and focus on – “Error”, ignore the tiny “Request Access” link, and call the help desk saying they can’t get to SharePoint. There is no error; this is the process we want them to use. Our Access Denied page needs to be more user-friendly.
This took much research and was a little scary for me, as it involved delving into Visual Studio instead of just using the SharePoint Designer. I was able to piece it together thanks to Vijai Anand (How to create custom SharePoint 2010 Application Page using Visual Studio 2010) and Soderlind (SharePoint 2010: Customize out of the box Application Pages (AccessDenied, Confirmation, Error, Login, RequestAccess, Signout, WebDeleted )) and a co-worker who helped with the CSS portion. This was developed on a Development Server (that had Visual Studio 2010 installed and SharePoint installed) and then deployed to our Test Server using PowerShell (the same will be used to go to Production.) I’m including all of the steps for the benefit of admins who are not developers.

Step 1: Make the page using Visual Studio.

File > New > Project

Empty SharePoint Project. (We use Team Foundation Server for our Source Control, so the part about “Add to Source Control” may not apply to you.)

Connect to your Development SharePoint application. Select “Deploy as a farm solution”.

Right-click the project, Add > New Item

Select Application Page and name your new page.

Now, because we want to retain the ability to “Request Access” and “Sign in as different user” and those parts are looking for pages relative to the called page, I’m going to move the ExampleAccessDenied.aspx out of the folder where it got created and delete the folder. This is because, if I don’t, the deployment will create a folder in the layouts directory and mess up my relative path.


Step 2: Modify the page

I want most of the functionality provided by the default Access Denied page so I’m going to copy and paste all of the code out of the OTB page into my own. Find the AccessDenied.aspx in the hive. (Typically: C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS)

Once you’ve replaced all the code in your page with the copied code, you can build and deploy your solution for a look at your progress. Right-click and build your solution.

Then right-click and deploy your solution. This will put a copy of the application page into the layouts folder of your web application.

You should be able to browse to your application page. It looks just like the Access Denied page.

Back to Visual Studio and the code on the page. I’m going with the assumption that you’re not a developer and most of this looks like Sanskrit. I’m going to show you section by section what was there and what I put so hopefully, if you want to make simple changes similar to mine, you’ll be able to figure it out. All the code, before and after, is included here: ExampleAccessDenied

PlaceHolderPageTitle

This is what puts the Error: Access Denied at the top of the Explorer bar and the tab window.

We want to replace the word Error with our company initials.

BTW, you can comment out sections by selecting the code and hitting the icon next to the tab-in tab-out icons. It puts the <%– marks around the commented code –%>

PlaceHolderPageTitleInTitleArea

This is the other Error: Access Denied we wanted to get rid of.

A friendlier You do not have access to this resource.

PlaceHolderPageImage

The very intimidating X; that’s got to go.

We’re just going to comment that section out altogether.

PlaceHolderAdditionalPageHead

This is where my co-worker helped me. We wanted to control the formatting of the section and needed a little brute force to get the error image to stop showing. Sorry I don’t have more commentary for this section, but hopefully you’ll be able to use what we did.

PlaceHolderMain

This is the main meat and potatoes section. We removed the icon, made a friendlier list of options, and moved the user info to the bottom. I’ve included the entire thing in a pdf you can download. ExampleAccessDenied
Build and deploy the solution again.

Package your solution
Change the configuration from Debug to Release.

Right-click and package the solution.

The output will show you where it put the wsp file. This is the file you will need to deploy to our other environments (because you DO follow an SDLC process right?)

Step 3: Tell SharePoint to use the new page

We do NOT want to just rename our page to AccessDenied.aspx.
cls $snapIn = Get-PSSnapin | where-object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}
if($snapIn -eq $null) { 
 Add-PsSnapin Microsoft.SharePoint.PowerShell 
} 
Set-SPCustomLayoutsPage -Identity "AccessDenied" -RelativePath "/_layouts/ExampleAccessDenied.aspx" -WebApplication "http://DEVWEBAPPLICATION" 
Get-SPCustomLayoutsPage –Identity "AccessDenied" -WebApplication "http://DEVWEBAPPLICATION " 
iisreset

Step 4: Deploy

In the new environment, put the wsp file into a temporary holding place. We used a folder called solutions. Then run the powershell to deploy the solution and Set SPCustomLayoutsPage. I have the powershell saved in a pdf for that as well (DeployCustomAccessDeniedPowershell.)
Set the variables at the top for the solution name, release folder name, and web applications you need to release to:
$allSolutions = (“CustomAccessDenied.wsp”)$releaseFolderName = “C:\Solutions\CustomABCD\”$allURLs = (“https://WEBAPP1&#8243;,https://WEBAPP2)
At the very bottom, you’ll need to change the aspx page as well:
“/_layouts/CustomAccessDenied.aspx”