Archive

For the SharePoint category

SharePoint 2010 Advanced 404 Page

No Comments

Based on this useful post I started to create my HttpModule to manage in a smarter way the 404 of SharePoint 2010.
The fact is simple: with the normal 404 configuration in the web.config you can’t manage all the paths, but only the fake page. It means  that if you type “http://mysite/fakepath” it will not work. Considering that the “MVC syntax” is today much more required it is important to manage the errors.

The only thing I didn’t like in the article above is how to change the status code of the page. For a SEO purpose it is important that a 404 page has the 404 HTTP Code and not the classical 200. In article is showed how to create a specific Web Part where explicitly we set the Response Code. It works, but in terms of dependencies and maintenance is not really the top.

Once of the big advantage  with SharePoint 2010 is that we work directly in the INTEGRATED MODE of IIS and we are directly in the pipe line of IIS. With this we can use the event PostRequestHandlerExecute and change the Status code here.

Enjoy! :)



 

 void _app_PostRequestHandlerExecute(object sender, EventArgs e)
        {
            HttpResponse __response = _app.Response;
            HttpRequest __request = _app.Request;

            if (__request.Url.AbsolutePath.Equals(myCustom404Url, StringComparison.InvariantCultureIgnoreCase))
            {
                __response.StatusCode = 404;
            }
        }

 

Convert an SPListItemCollection to an IEnumerable

No Comments

In one of my last project I make a function to accept an IEnumerable<T> as parameter. I normally used this function with PublishingPageCollection. This collection inherits from QueryBasedCollection<PublishingPage> and so it is a IEnumerable. Unfortunately the SPListItemCollection it is not.

I didn’t want to change my method and I didn’t want to create an overload only for the type of parameters. Then…I remembered that LINQ is my friend :)
You can directly convert an SPListItemCollection. Below an example…hope can help you…

using (SPWeb web = SPContext.Current.Site.OpenWeb("myweb"))
{
       return web.Lists["MyList"].Items.Cast<SPListItem>().Select(item => item);
}

SharePoint 2010 – Modal Dialog and strange behavior with the dialog.master

No Comments

In SharePoint 2010 is available the object SP.UI.ModalDialog.You’ll have so the modal dialog windows of SharePoint 2010 available for your application page. That’s cool.

To open the modal dialog you execute the JavaScript code below (you can even add some callback event)

function OpenDialog(strPageURL, delegate, w, h) {
var dialogOptions = SP.UI.$create_DialogOptions();
dialogOptions.url = strPageURL; // URL of the Page
dialogOptions.width = w; // Width of the Dialog
dialogOptions.height = h; // Height of the Dialog
dialogOptions.dialogReturnValueCallback = Function.createDelegate(null, delegate); // Function to capture dialog closed event
SP.UI.ModalDialog.showModalDialog(dialogOptions); // Open the Dialog
return false;
}

To do that you have available the Dialog.master master page. It’s a normal master page with specific content place holder.
The problem I had is that if you have for example a flow of pages in the modal dialog, after a redirect, sometime the HEADER of the modal dialog  just disappears. And it does that not everywhere, but just with the Team Site. I don’t know really why, I think it’s something closer to a bug that a feature :) . By the way you can easily solve the problem. Avoid the Dialog.master and, instead, you use a normal ApplicationPage, with the Default.master and you execute the url with the parameter IsDlg=1 in the query string. You’ll have the same behavior of the modal  dialog, but we won’t have the disappeared header. Below you have an image of the problem.

In the first image the header is fine, but then, if you change page you just lose it…

 

 

 

 

 

 

And here the problem

 

 

SharePoint 2010: error crawling People

No Comments

Today I figured out a funny problem. When you know it’s easy, but I lost an hour to understand what the hell was going on.
In my SharePoint 2010 Farm everything was going fine…I installed and configured the User Profile Synchronization, the MySite was well configured in a specific Web Application. I needed to search people so I went to the Central Administration > Management Application >  Service Application > Search Service Application and start the Full Crawl.

Unfortunately once ended the Full Crawl I had this error on the log:

sps3://SERVERNAME
Error in PortalCrawl Web Service

I started to search and really don’t understand why…In the ULS I found this error:

PortalCrawl.GetSite(): System.NullReferenceException:
Object reference not set to an instance of an object.
at Microsoft.SharePoint.Portal.Search.
PortalCrawl.PortalCrawl.GetSite(_PortalSite& sSite).

and I finally got it. The default site in SharePoint http://SERVERNAME on port 80 must be created and a site collection must be too, otherwise you’ll problem will be not solved. Honestly in my configuration I never use the default web site, because I use personalized DNS, but since today I’ll do always :)
Now my scope “People” is well done:

 

Hope this can help,

M.

 

Ideal configuration for SharePoint 2010 dev environement

1 Comment

In my experience when you develop an application in SharePoint 2010 you should have environment the most close possible to the client configuration. This means that the classical URL http://mysrv:4354 or http://mysrv:3145/sites/mycoll are not the best configuration you can have.

Beside that even to work with a local user is really not the best…you can develop something that locally works like a charm, but when you’ll install into the client farm you’ll be quite surprised.
I would like so to share my configuration with you and I hope you can find something interesting in that. Of course, I’m not the “inventor” of this configuration, but it’s just my “best practice”.

  1. VM Ware machine with Win2008 R2 installed with the scope of Primary Domain Controller, with 512 MB  of RAM
  2. VM Ware machine with Win2008 R2, SQL Server 2008 R2 and SharePoint 2010 installed as a Single Server Farm , with 4096 GB of RAM

 

Primary Domain Controller

The primary domain controller will be an “easy” machine, configured as below, where the DNS server is installed and configured.
To install the DNS server, please take a look to this link

Once you have installed the DOMAIN, please create the following users:

  • SPAdmin: he will be the farm administrator of you SharePoint installation
  • AppPool: he will run the application pool of your web applications
  • DBAmin: he will be the administrator of the database server
  • Guest1, Guest2 and Guest3: you can use these users to configure different users of your site collections. It is very important you make your test with different roles.

Forward Lookup Zone

As I said above, for my experience you should have, as host header a real configuration and the OOB URL of SharePoint they aren’t. It’s not so hard, by the way, to have this feature.

  • Open your DNS manager
  • Open the item Forward Lookup Zone and open you domain item too
  • In order to have your items well organized create a new domain named SHAREPOINT. You’ll save here your host headers. When you create a new host header you’ll associate the name with an IP address you’ll set in the SharePoint machine.

SharePoint Server

Once you installed your new virtual machine with Windows 2008 R2 and SqlServer 2008 you have to add to the domain. In order to achieve this goal you have to add a new Network Adapter and configure as HOST ONLY.

When you have your new network adapter you’ll configure the IPV4 in order that your Active Directory machine will be the DNS server. You’ll add, after that, all the IP address you choose for the host headers. (Click ADVANCE in the main windows of IPV4).




After all these steps if you try to PING your host header by name (ex. das.sharepoint.sintax.local) you’ll obtain the response of your main SharePoint machine.

To install SharePoint I think is not necessary any specification. You’ll find on the Microsoft site all you need. My points are just when you’ll configure your new web application. We created a DNS specific for one web application: this means we can use our web application in the 80 port. See the image below and you’re done :)

In my experience this configuration can really help you to make your application with a real environment, most similar to the client configuration than the OOB SharePoint url and host header.

Blue Taste Theme created by Jabox