JavaScript/JQuery – How to retrieve resources translations in JS

In your JS code write you can write the following literal declaration into a JS variable.

var data = “<asp:Literal runat=”server” Text=”<%$Resources:myresourcefile,resourcetitle%>” />”;

Then you can use the value in the data variable to lets say hide something in your page based on a translation. In the following example I hid a certain breadcrumb information based on different languages.

$(“#breadcrumb ul li a:contains(” + code + “)”).hide();

Advertisements

Tips: SQL Server – Constraints and Functions

If you are planning to make a table constraint that is more complex than a simple check against a field or two then I recommend using functions. By creating a function you can make complex logic by which you can return True Or False states that indicate to a constraint if the data is what you need it to be. You can also add parameters to a function giving you the dynamic possibility to process data being processed.

Example:

Lets say that you have function that wants to check if a ID value is a certain numeric ID and then you want to make sure that a row being inserted does not have a NULL value in a certain field.

Here is some sample code:

CREATE FUNCTION [dbo].[CheckForNullByID]

(

   — Add the parameters for the function here

   @someID int,

   @someFieldNotNULL char(11)

)

RETURNS bit

AS

BEGIN

   DECLARE @retValue bit = 0

   IF @someID = 40

   BEGIN

          IF @someFieldNotNULL IS NOT NULL

          BEGIN

                 SET @retValue = 1

          END

          ELSE

                 SET @retValue = 0

   END

   ELSE

          SET @retValue = 1

   RETURN @retValue

END

GO

Then you call the function in your constraint like the following expression:

([dbo].[CheckForNullByID]([rowIDValue],[someFieldValueThatIsNotToBeNULL])>(0))

Thats it :)!!!

Hope this helps 🙂

Good to Know: Windows Server 2012 – Part 2

Part 2 of the good to know things of Windows Server 2012:

Backup using GPMC http://technet.microsoft.com/en-us/library/cc784474(v-ws.10).aspx
View Hidden Folders in Active Directory Users And Computers http://technet.microsoft.com/en-us/magazine/gg456494.aspx
Add-PswaAuthorizationRule http://technet.microsoft.com/en-us/library/jj592890(v-ws.10).aspx
Software Restriction Policies Rules http://technet.microsoft.com/en-us/library/hh994597.aspx#BKMK_Cert_Rules
How manage Published (a.k.a Metro) Apps in Windows 8 using Group Policy http://www.grouppolicy.biz/2012/08/how-manage-published-a-k-a-metro-apps-in-windows-8-using-group-policy/
Understanding Connection Security Rules http://technet.microsoft.com/fi-FI/library/dd448591(WS.10).aspx
How to Enable Authenticated Firewall Bypass http://technet.microsoft.com/en-us/library/cc753463(v=ws.10).aspx
Filter the scope of Group Policy according to security group membership http://technet.microsoft.com/en-us/library/cc786636(WS.10).aspx
Block Inheritance – GPO http://technet.microsoft.com/en-us/library/cc731076.aspx
WMI filtering using GPMC – GPO http://technet.microsoft.com/en-us/library/cc779036(v=ws.10).aspx
User Rights Assignment http://technet.microsoft.com/en-us/library/cc780182(v=ws.10).aspx
Windows Authorization Manager http://msdn.microsoft.com/en-us/library/bb897401.aspx
Backing up, Restoring, Migrating, and Copying GPOs http://technet.microsoft.com/en-us/library/cc781458(v=WS.10).aspx
Group Policy Cmdlets in Windows PowerShell http://technet.microsoft.com/en-us/library/hh967461.aspx
Copy-GPO http://technet.microsoft.com/en-us/library/ee461050.aspx
Import-GPO http://technet.microsoft.com/en-us/library/ee461044.aspx
Port Virtual Local Area Network (PVLAN) and Trunk Mode http://technet.microsoft.com/en-us/library/jj679878.aspx#bkmk_portmirror 
Backing Up and Restoring Virtual Machines http://msdn.microsoft.com/en-us/library/dd405549(v=vs.85).aspx 
Backing Up Hyper-V Virtual Machines http://blogs.technet.com/b/virtualization/archive/2008/08/29/backing-up-hyper-v-virtual-machines.aspx 
Resource Metering http://technet.microsoft.com/en-us/library/hh831410.aspx#BKMK_resourcemetering
Hyper-V Resource Metering in Windows server 2012 http://blogs.technet.com/b/meamcs/archive/2012/05/28/hyper-v-resource-metering-in-windows-server-2012-server-8-beta.aspx
Windows Deployment Services http://technet.microsoft.com/en-us/library/cc766320(v=ws.10).aspx
New-ADComputer http://technet.microsoft.com/en-us/library/ee617245.aspx
Djoin http://technet.microsoft.com/en-us/library/ff793312(v=ws.10).aspx
Dsadd http://technet.microsoft.com/en-us/library/cc753708(v=ws.10).aspx
Add-Computer http://technet.microsoft.com/en-us/library/hh849798.aspx

Changing Active Directory user passwords in a .NET Web Application

Here are some tips on how to allow your web application to change passwords to Active Directory. There are several ways which all work in a similar but different way. This is one of them and what you need to take into consideration.

Here I will concentrate in the code logic and configurations what you need to take and do.

These are the following steps you need to take:

1. Create a web form for you password reset

2. Create a account with just enough privileges to set or reset user passwords

3. Impersonate this account and reset or set a new password under this password “admin” account

And a small sample code on how to change a password:

using (var context = new PrincipalContext(ContextType.Domain, “domain”, “username”, “password”))

 {

     using (var user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, “username whose password to change”))

      {

                                    user.SetPassword(“newpassword”);

//// or

                                    //user.ChangePassword(“oldPassword”, “newpassword”);

                                    user.Save();                                 

       }

}