Today I had a bit of a nightmare when trying to ensure that the AlternateHeader of a web was set to blank (it had previously had a custom header applied). Unfortunately I could not find a simple solution to this, and unfortunately had to resort to altering the sharepoint db (this is not recommended / supported by Microsoft).
The following code does not behave as expected:
currentWeb.AlternateHeader = "";
It would appear that when the AlternateHeader is set (as above), the stored proc “proc_UpdateTpWebMetaData” is called (in the xx_SITE database). This contains the following check:
AlternateHeaderUrl = CASE WHEN @AlternateHeaderUrl IS NULL THEN AlternateHeaderUrl ELSE @AlternateHeaderUrl END,
There are two solutions to the issue:
The first one is too modify the stored proc, removing the check – i.e. AlternateHeaderUrl = @AlternateHeaderUrl END, (note that I am not sure what implications this may have on other areas of the code).
The second solution is to simply edit the webs table in the sharepoint xx_SITE database. Simply select the relevant list item in enterprise manager and reset its AlternateHeader value.
Sending emails with c#.net was actually surprisingly easy (note that I only tested it on an asp.net form in Server 2003). Adding attachments etc was also surprisingly easy (no need to worry about mime boundaries etc).
The machine that the application is running on must be running an SMTP service (this can be set up with the Server Configuration Wizard). Once this is set up, you must allow relay access from localhost…
- Go to: start > settings > control panel > Administrative Tools > Internet Information Services
- Expand the ” (local computer)” node
- Right click on your SMTP server > go to “Properties”
- Click “Access” tab
- Under Relay Restrictions, click the “Relay” button
- Click “Add”
- Select “Single Computer” and enter IP address 127.0.0.1
- Hit OK, OK, OK (until the properties dialog is closed)
Actually Sending Emails
Add “using System.Web.Mail;” to the top of the relevant file
MailMessage mail = new MailMessage();
mail.To = "email@example.com";
mail.From = "firstname.lastname@example.org";
mail.Subject = "Contact from website";
mail.Body = "Email body";
SmtpMail.SmtpServer = "localhost";
I wont go on too much about sending attachments – its all pretty well explained at http://www.codersource.net/csharp_sending_emails.aspx
Stop press – sending with .net 2
If you are using windows SMTP be sure that any line ending characters in the message are of the form \r\n and not just \n. I have had issues in the past with relay servers failing to send wrongly formatted line endings. Apparently 822bis (not sure what this is) specifically prohibits other uses of LF.
The GAC is essentially visible as a special folder, normally residing at C:\Windows\Assembly. It can only contain assemblies, and these assemblies must be strongly named. The assemblies within the gac are essentially dlls that can be used by all applications on the computer – note that the various .net assemblies appear in the gac – e.g. system.text.
Note that assemblies dragged and drop into the gac folder are only referenced by the gac, the actual assemblies still reside in their original location. To actually copy an assembly to the gac, you must use gacutil.
A strong named assembly is one that has been signed via a public key (part of a keypair). A keypair can be generated with the strongly naming tool (that comes with visual studio / .net). Note that you can assign an assembly when built (providing you have a keypair) – by specifying certain attributes in the projects assemblyinfo.cs file. Once an assembly has been strongly named, you can simply copy it to the gac location – it will then be available to all applications.
Note that delay sign means that the assembly can be signed later (if say only an administrator, not a developer has access to the relevant private key / certificate.
Also note that if you just strongnaming an assembly, you don’t need to distribute a public key or similar.
Also note that assemblies in the gac cannot be reference in visual studio (or at least easily – without editing registry keys etc). Instead, you must reference a copy of the relevant dll locally (so the dll should exist locally). Note that once the relevant project using that reference is build, you no longer need the dll locally if it resides in the gac. This is because assemblies are searched by fusion.dll runs (which controls the gac). This looks in the gac for an assembly before it looks locally.
Note that these notes are very rough atm, i will hopefully tidy them up and add more info at some point.
Search engine optimisation. Although the main search engines are continually tweaking their ranking algorithms, by following a few principles can ensure that your site features as highly as possible in search engine results. This documents is a set of rough notes on how to ensure your site gets the highest possible rankings with search engines.
- Google normally picks up your site when other sites link to it, however you can submit your site using this page… http://www.google.com/addurl.html
- Ensure that no robots.txt or meta robots tags restrict spiders from parts of a site that you want indexed
- Google page rankings have recently been altered, so that links from directories and adverts are greatly reduced in importance (eg froogle etc)
- Make sure the body text of the site contains keywords and phrasing that you want your site to appear under (at about 5-10% keywords in copy)
- Submit your site to the dmoz directory (used by yahoo and google). Dmoz (also known as the open directory project) is a directory that is manually maintained by administrators, who maintain the quality of links etc, instead of being created by bots (like most other directories). Google seems to rank links from this highly (as it is a pet project related to google). Please note that as the directory is edited and updated by people, it can take in excess of several months to get listed.
- Make sure as many people link to you as possible. Recipricate links (google rates such links higher) This is one the single most important thing it getting a good search engine ranking. The page rank of the sites that link to you is also important. Note that also rates the speed at which your site gains links and the link life span. The anchor text of each link is also important and should contain keywords that you expect people to search for (no more than 5-10 words though). Links must be grown slowly – google assumes sites that are suddenly linked by 100’s of other sites are spammers.
- Meta keyword tags are not really used by any search engines now, however it is good practice to ensure that you have them. These should also not be excessively long. The meta description of the site must also be added as this is what is shown by a lot of search engine in search results.
- make sure that the title tag is set and is relevant to the pages
- Ensure that the site has logical clear structure, with h1’s h2’s etc. To many levels of nesting (eg if your using tables) can adversely affect your search listings. If possible use divs for positioning and only use tables for tabular data.
- Google seems to look at the ip address of the server that your site is listed on, hence google will not rate highly links to other sites on that server.
- Google also seems to look at how long a domain has been registered for. Domains registered for 1 year are generally typical of spammer sites etc, so register your domain for more than 1 year.
- Google ranks sites that have been established longer higher. So the older your site, the higher the potential ranking.
- Google adversely rates multiple domain names pointing at one site, and may even block sites from its listings that do this excessively.
- Click through rates, caches of client browser are also monitor via the google toolbar, hence sites
- Google adversely looks upon sites that have hidden text eg. by display=none in the style sheet. It assumes that sites doing this have been coded to trick google into ranking it for words that are not scene by the user. Google is also becoming more advance on its detection of text hiding tricks.
- Update text regularly, google seems to notice the positioning of keywords within the text, so alter accordingly
Please note that google can take a few months before your site appears stable within listings. Only the homepage is initially shown in the google rankings.
For information on how google indexes, see http://www.google.com/bot.html#howoften
Google algorithm details http://www.buzzle.com/editorials/text6-10-2005-71368.asp
Search engine watch http://www.searchenginewatch.com
Search engine world http://www.searchengineworld.com
SEO chat http://www.seochat.com/