Thursday, September 22, 2011

How to: Set Up Database Access via Visual SourceSafe (Internet or Remote)


Visual Studio 2005


Visual SourceSafe (Internet) plug-in can be configured to access a Visual SourceSafe database either on the same computer where the Visual SourceSafe Web service is running or on another computer. In the latter case, both the Web service computer and the computer that is hosting the database must reside inside the same Windows domain.

Setting Up Internet Access on the Same Computer as the Web Service

To set up access on the same computer as the Web service

  1. IIS is required to run the Internet service. If it is not installed, see How to: Enable Internet Information Services (IIS).
  2. In Visual SourceSafe Administrator, on the File menu, click Open SourceSafe Database.
  3. Create a network share.
  4. Through the share you created in the previous step, open the database for which you want to enable remote access.
  5. On the Server menu, click Configure.
  6. In the Server Configuration dialog box, click Remote Access.
  7. Select the Enable remote access for this computer check box to enable the Internet service for the server computer.
  8. Choose Enable remote access for this database to allow remote access to the database you have specified.
  9. (Optional) You can require secure communication using SSL, as described in How to: Set Up Secure Sockets Layer (SSL). Use of SSL is strongly recommended.
  10. In Web Server Name, type the name of the Web server. You can enter either a DNS name or an IP address.
  11. Click OK to apply your settings.
  12. Repeat this procedure, if needed, for any other databases.
  13. Notify any users of the SourceSafe Internet plug-in in Visual Studio that the service is enabled and they can start accessing the Visual SourceSafe database through the web service. Make sure that you provide clients with the name of the server to connect to and the name of the share where VSS database is shared. For more information, see Using Visual SourceSafe in Microsoft Visual Studio.

Setting Up Internet Access on a Different Computer than the Web Service

This section describes how to configure Microsoft SourceSafe Internet plug-in to access a database on a file server computer that is different computer from the one VSS Web Service is running on. Two procedures are provided: one for setting up access for a new database, and one for setting up access for an existing database.
  • Enabling Internet Access for a new database. This procedure describes how to configure Internet access for a database on another computer by enabling Internet access for the database while the database is stored on the same computer (the Web server) and then moving the database to another computer (the File server).
  • Enabling Internet Access for an existing database. If you need to configure an existing database, this procedure describes how to configure Internet access to an existing VSS database located on a computer (the File Server) different from the computer running VSS Web Service.

To set up access on a different computer than the Web service

  1. Create the VSS database on the web server.
  2. Enable Internet Access for the database. For more information, see How to: Enable the Internet Service for Remote Access.
  3. Move the VSS database to the File Server by copying all the files in the database to a folder on the file server.
  4. Create a network share, and assign user access rights to the share. For more information, see the article "Locking Down Your Database (Visual SourceSafe)" on MSDN.
  5. Correct the IIS virtual folder paths to point to the new location as follows:
    1. Open the srcsafe.ini file and note the values for the DownloadVDir and UploadVDir variables.
    2. In Internet Information Services manager, find the virtual folders listed in srcsafe.ini file under Default Web SiteSourceSafe.
    3. Select the download folder (from the DownloadVDir variable noted in step 7), and select Properties.
    4. In the Properties dialog, on the Directory tab, change Local Path to point to the new database location download file:new_database_location\VssWebDownload (for example, \\FileServer\Database\VssWebDownload).
    5. Select the upload folder (from the UploadVDir variable noted in step 7), and select Properties.
    6. In the Properties dialog, on the Directory tab, change Local Path to point to the new database location upload file:new_database_location\VssWebUpload (for example, \\FileServer\Database\VssWebUpload).
  6. Correct the web configuration file as follows:
    1. Open the web.config file from your Visual SourceSafe installation folder in the \VSSWebService folder (for example, C:\Program Files\Microsoft Visual SourceSafe\VSSWebService).
    2. Find the section <Add key=”Database_path”> that points to the database.
    3. Modify the path for the database to point to the new location. (For example: <Add key=”\\FileServer\Database">)
    4. Save the web.config file.
  7. Configure authentication delegation for the server as follows:
    1. Open Active Directory Users and Computers.
    2. In the console tree, click Computers.
    3. In the details pane, right-click the computer running the VSS Web Service and then click Properties.
    4. On the Delegation tab, check the Trust this computer for delegation to specified services only box.
    5. Confirm that Use Kerberos only is checked.
    6. Click Add, and in the Add Services dialog box, click Users and Computers.
    7. In Enter the File Server name, enter the file server name, and then click OK.
    8. In the Add Services dialog box, select service “cifs,” and click OK.
  8. After completing these steps, you should be able to connect to the web service using the Visual Studio Plug-In.

To enable Internet Access for an existing database on a different computer than the Web service

  1. Create a new VSS database on the web server.
  2. Enable Internet Access for the existing database. For more information, see How to: Enable the Internet Service for Remote Access.
  3. Create folders in the existing database to upload and download files as follows:
    1. In the database location, create a \VssWebDownload folder (for example, \\FileServer\Database\VssWebDownload).
    2. In the database location, create a \VssWebUpload folder (for example \\FileServer\Database\VssWebUpload).
  4. Add the Web service URL to srcsafe.ini file as follows:
    1. Open the srcsafe.ini file in the temporary database.
    2. Find the variable Web_Service pointing to the VSS web service (for example, Web_Service = http://vss.microsoft.com/SourceSafe/VssService.asmx)
    3. Copy this line into the srcsafe.ini file of the existing database.
  5. Correct the IIS virtual folder paths to point to the new location as follows:
    1. Open the srcsafe.ini of the database that was created on the Web Server and copy the lines for the DownloadVDir and UploadVDirvariables.
    2. Paste these lines into srcsafe.ini file of the existing database.
    3. In Internet Information Services manager, find the virtual folders listed in srcsafe.ini file under Default Web SiteSourceSafe.
    4. Select the download folder (from the DownloadVDir variable noted in step 7), and select Properties.
    5. In the Properties dialog, on the Directory tab, change Local Path to point to the database location download file:new_database_location\VssWebDownload (for example, \\FileServer\Database\VssWebDownload).
    6. Select the upload folder (from the UploadVDir variable noted in step 7), and select Properties.
    7. In the Properties dialog, on the Directory tab, change Local Path to point to the database location upload file:new_database_location\VssWebUpload (for example, \\FileServer\Database\VssWebUpload).
  6. Correct the web configuration file as follows:
    1. Open the web.config file from your Visual SourceSafe installation folder in the \VSSWebService folder (for example, C:\Program Files\Microsoft Visual SourceSafe\VSSWebService).
    2. Find the section <Add key=”Database_path”> that points to the database.
    3. Modify the path for the database to point to the new location. (For example: <Add key=”\\FileServer\Database">)
    4. Save the web.config file.
  7. Configure authentication delegation for the server as follows:
    1. Open Active Directory Users and Computers.
    2. In the console tree, click Computers.
    3. In the details pane, right-click the computer running the VSS Web Service and then click Properties.
    4. On the Delegation tab, check the Trust this computer for delegation to specified services only box.
    5. Confirm that Use Kerberos only is checked.
    6. Click Add, and in the Add Services dialog box, click Users and Computers.
    7. In Enter the File Server name, enter the file server name, and then click OK.
    8. In the Add Services dialog box, select service “cifs,” and click OK.
  8. After completing these steps, you should be able to connect to the web service using the Visual Studio Plug-In.

Wednesday, September 21, 2011

Using cookies with jQuery


Cookies aren’t just tasty and chocolate-flavoured. They can also store useful information for your users to have a better experience on your site. They are jQuery flavoured too. In this tutorial we will learn how to use jQuery and cookies to store some user preferences in a cookie to display an specific content to the user. So, grab one of your favourite cookies and read on.

Starting

What we are going to do is just a panel with a series of labels. Each time you click one of them, it will be highlighted and the name of the selected label will be stored in a cookiein your computer through your browser. After that, you can use two buttons to display the value that the cookie currently contains or simply delete the cookie.
In addition, look at the application the first time you load the demo page. None of the labels are selected. Now, after you select one, you can reload the page and see that the label you selected before is still selected. If you delete the cookie now it will be deselected. After reloading the page you will see that no label has been selected. Ok, time to watch it in action. Try it, play around

Handling cookies with jQuery

We are going to use jQuery to handle our cookies and we will also be using a free jQuery plugin that specifically deals with cookie storage, aptly named, Cookie.
Download Cookie plugin from jQuery projects area.
Cookie is a simple plugin with only one function, Cookie(). With this function you will write, get and delete cookies on your computer.

The markup

After including the jQuery library, we will include the jquery.cookie.js plugin in our HTML. After that, include your JavaScript file or just type it in a <script> tag.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="jquery.cookie.js"></script>
<script type="text/javascript" src="general.js"></script>
In terms of HTML this snippet is really simple:
<ul>
  <li>
    <h2>
      <a href="#basic" id="basic">Basic</a>
    </h2>
  </li>
  <li>
    <h2>
      <a href="#intermediate" id="intermediate">Intermediate</a>
    </h2>
  </li>
  <li>
    <h2>
      <a href="#advanced" id="advanced">Advanced</a>
    </h2>
  </li>
</ul>
<a href="#" id="showCookie">Show cookie</a>
<a href="#" id="deleteCookie">Delete cookie</a>
<input disabled id="verbose" type="text" />
We’re writing three labels, a couple of anchors and an input, to output the state of the cookie. The CSS is irrelevant since it is only used to highlight the selected label applying the .selected class. Let’s jump straight to the fun part.

jQuery Cookies – Creating the cookie

So, first things first, add the usual snippet to execute our jQuery when the document is ready:
jQuery(document).ready(function(){
     //code goes here
)};
Now, let’s initialize a couple of variables to use them through our code. These are the cookie’s name and a set of options to pass on the cookie function: expiration time and a path, which can be a url from a page. there are other arguments but for the sake of clarity, we will only use these two:
var cookieName = 'level';
var cookieOptions = {expires: 7, path: '/'};
Next, let’s see if our cookie has its value set. If it doesn’t, it’s ok, never mind. But if it does, add the .selected class to the label whose ID is stored in the cookie. We use thecookie function with a single parameter, the name of the cookie whose value we want to retrieve:
$("#" + $.cookie(cookieName)).addClass("selected");
We will be building a click event now. The preventDefault() function is a standard jQuery procedure to prevent anchor jumping on the browser when you click a link. When a user clicks the label (which is actually an anchor), we will remove the .selected class from the label where it’s currently applied and add it to the clicked label.
$(".htabs a").click(function(e){
e.preventDefault();
$("#" + $.cookie(cookieName)).removeClass("selected");
Time to create a cookie and assign it a value. First argument is the cookie name, which is level, the second one is the value that we will assign to it, which is the name of the label. We will also pass the options set that we wrote before.
$.cookie(cookieName, $(this).attr("id"), cookieOptions);
Now let’s simply add the .selected class to the label:
     $("#" + $.cookie(cookieName)).addClass("selected");
});

jQuery Cookies – Retrieving and displaying the cookie’s value

We now want to output the value of our cookie. All the we need to do is to call cookiefunction without any other parameter than the name of the cookie we want to inspect. When the #showCookie button is clicked, we will write the value currently stored in the cookie on the #verbose field.
$("#showCookie").click(function(e){
  e.preventDefault();
  $("#verbose").val("Cookie value is " + $.cookie(cookieName) + ".");
});

jQuery Cookies – Deleting the cookie

Now we reach to the point when we want to delete the cookie. So, when the#deleteCookie button is clicked we will output on the #verbose field the name of the cookie being deleted. Then we remove the .selected class from where it’s currently applied.
$("#deleteCookie").click(function(e){
  e.preventDefault();
  $("#verbose").val("Cookie 'level' with value \"" + $.cookie(cookieName) + "\" removed.");
  $("#" + $.cookie(cookieName)).removeClass("selected");
Finally we will delete the cookie, and this is an interesting step. The code goes simply like:
$.cookie(cookieName, null);
Ok, no big deal right? This is correct. In fact, this is the way shown on the Cookie plugin example page. However,
when you do this and pass in the cookieOptions variable as a third argument, theexpires variable of cookieOptions is set to -1. Inspect the code for jquery.cookie.js and you will find this:
if (value === null) {
  value = '';
  options.expires = -1;
}
Why is this important? because if you pass cookieOptions as a third argument and were to create a new cookie right now using
$.cookie(cookieName, $(this).attr("id"), cookieOptions);
it would not work, because cookieOptions.expires has been set to -1, which according to the description found on the plugin:
If a negative value is specified (e.g. a date in the past), the cookie will be deleted


That’s it, we’ve reached the end:
   });
});
Play with the demo, click the labels, output the value, reload the page, close the tab and open it again, delete the cookie, etc.
Here’s the complete code for close inspection.
I hope you’ve enjoyed this and see you next time for more jQuery goodness.