[Umbraco] Add User with hashed password & check unique loginname

protected static bool addUmbracoUser(string loginName, string userName, string password)
{
if (ensureUniqueLoginName(account))
{
User u = umbraco.BusinessLogic.User.MakeNew(userName, loginName.Trim(), hashPassword(password), new List < UserType> ());
u.addApplication("content");
u.addApplication("media");
u.addApplication("users");
u.addApplication("settings");
u.addApplication("developer");
u.addApplication("members");
u.Save();
return true;
}
else
{ return false; }
}

private static bool ensureUniqueLoginName(string loginName)
{
umbraco.BusinessLogic.User[] u = umbraco.BusinessLogic.User.getAllByLoginName(loginName);
if (u.Length != 0)
{
return false;
}
return true;
}

private static string hashPassword(string password)
{
HMACSHA1 hash = new HMACSHA1();
hash.Key = Encoding.Unicode.GetBytes(password);

string encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)));
return encodedPassword;
}


Reference: http://our.umbraco.org/wiki/reference/api-cheatsheet/users,-user-types-and-permissions/add-user-with-hashed-password

RadControls – RadGrid export to Excel with text format


void btnExport_Click(object sender, ImageClickEventArgs e)
{
rgGrid.ExcelExportCellFormatting += new OnExcelExportCellFormattingEventHandler(rgKBuser_ExcelExportCellFormatting);
rgGrid.MasterTableView.ExportToExcel();

}
void rgKBuser_ExcelExportCellFormatting(object sender, ExcelExportCellFormattingEventArgs e)
{
e.Cell.Style["mso-number-format"] = @"\@";
}

Reference: http://www.telerik.com/help/aspnet-ajax/grid-html-export.html

Security issue – HttpResponse.Redirect in Umbraco appear trace information


If use below solution to implement redirection on your site.
Please ensure hack ~/default.aspx to disable the trace parameter.
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="True" Inherits="umbraco.UmbracoDefault" trace="false" validateRequest="false" %>
Please use web debugging tool to check your umbraco site , e.g. Fiddler
You can fellow below step .
1. open Fiddler
2. visit the redirect URL .  
3. in WebView tab , will appear all trace information , like Server Variables , Session State

IIS 7 To export/import a single website

Step1 Export:
%windir%\system32\inetsrv\appcmd list site “MyWebsite” /config /xml > c:\mywebsite.xml

Step2 Hack xml:
Hack name & id attributes in second site element , c:\mywebsite.xml

e.g.
<site name="mywebsite" id="1" serverAutoStart="true">
to
<site name="mywebsite2" id="2" serverAutoStart="true">

Step3 Import:
%windir%\system32\inetsrv\appcmd add site /in < c:\mywebsite.xml

Reference: :http://www.microsoftpro.nl/2011/01/27/exporting-and-importing-sites-and-app-pools-from-iis-7-and-7-5/


Note for purpose of create new website and keep original website

  1. Manually add new application pool & set new applicationPool to your website.
  2. Set attribute of serverAutoStart to “false”
  3. Set new attribute to bindingInformation.

[Umbraco] Ensure/Check unique user LoginName


private static bool ensureUniqueLoginName(string loginName)
{
umbraco.BusinessLogic.User[] u = umbraco.BusinessLogic.User.getAllByLoginName(loginName);
if (u.Length != 0)
{
return false;
}

return true;
}

[Umbraco] Add more than one TinyMCE datatype on page or usercontrol

        private void addTinyMCEControl(Control targetPlaceHolder, TabPage tp)
{

DataTypeDefinition htmlEditorDataType =
DataTypeDefinition.GetDataTypeDefinition(new Guid("A521511A-7BEE-4C5B-8D7B-4B06B57392B3"));

//The other way can get datatype id directly.
//DataTypeDefinition htmlEditorDataType = DataTypeDefinition.GetDataTypeDefinition(-87);

TinyMCE umbracoTinyMCEEditor = (TinyMCE)htmlEditorDataType.DataType.DataEditor;

string toolbar_id = string.Empty;

if (umbracoTinyMCEEditor != null)
{
if (umbracoTinyMCEEditor.config["umbraco_toolbar_id"] != null)
umbracoTinyMCEEditor.config.Remove("umbraco_toolbar_id");
toolbar_id = "tinyMCEMenu_" + targetPlaceHolder.ClientID;
umbracoTinyMCEEditor.config.Add("umbraco_toolbar_id", toolbar_id);
targetPlaceHolder.Controls.Add(umbracoTinyMCEEditor);
tp.Menu.NewElement("div", toolbar_id, "tinymceMenuBar", 0);
}
}


Reference:


[LINQ] Get child controls


using System.Collections.Generic ;
using System.Linq;
///
/// Get all child & sub-child controls within a control by type
///

/// The control we're searching in form/page.
/// The control type we're looking for (i.e; TextBox)
///
public IEnumerable < Control > GetAllChildControls(Control control, Type type = null)
{
var controls = control.Controls.Cast< Control >();

if (type == null)
return controls.SelectMany(ctrl => GetAllChildControls(ctrl, type)).Concat(controls);
else
return controls.SelectMany(ctrl => GetAllChildControls(ctrl, type)).Concat(controls).Where(c => c.GetType() == type);
}



//How to use.
IEnumerable< Control > textBoxControls = GetAllChildControls(this, typeof(TextBox));
IEnumerable< Control > allConrols = GetAllChildControls(this);


Reference : http://www.dreamincode.net/code/snippet5634.htm