ASP.NET Web Site Administration Tool

The ASP.NET Web Site Administration Tool / Membership Provider which is used along with the SQL Server Membership Database, is no longer available in VS 2013 because the Cassini web server is no longer supported. You can either get the Web Site Admin Tool up and running using a command window or set it up in IIS.  This post covers both cases (I prefer to use IIS vs. Command Window).

Other Tools: If you looking for a tool to manage users with ASP.NET Entity take a look at ASP.NET Membership Reboot.  At this link is another approach using Identity Manager and discusses Membership Reboot as well. 
 

 
1. Launch the Web Site Admin Tool using a command window:
  • Open a Command Window running it as a Admin
  • Change the folder to IIS Express cd C:\Program Files\IIS Express\
  • Run the following command to start up IIS Express
    • iisexpress.exe /path:C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles /vpath:"/ASP.NETWebAdminFiles" /port:8082 /clr:4.0 /ntlm
  • Access the Admin Site via the following URL:
    • http://localhost:8082/asp.netwebadminfiles/default.aspx?applicationPhysicalPath=C:\[YOUR SITE PATH HERE]\&applicationUrl=/ 
 
2. Launch the Web Site Admin Tool using IIS:  You can try running the site from the Windows folder but after a couple of issues I just moved it to another folder.  The steps below cover that process.
  • Copy the Admin Site from the following folder: C:\Windows\Microsoft.NET\Framework\v4.0.30319\ASP.NETWebAdminFiles
  • Change the web.config to allow any user to access the site  <allow users="?" />
  • Setup the site in IIS. Set the Authentication as shown below.  Use the following URL to manage your ASP.NET site. 
  • http://localhost/ASPNetAdmin/default.aspx?applicationPhysicalPath=C:[YOUR SITE PATH HERE]\&applicationUrl=/
 

Show Progress Message / Call ASP.NET Button Click from JavaScript

I have a batch process that runs on a background thread on an ASP.NET site. When that batch process runs I did not want the users to access specific features of the site. If you want to read more about running batch jobs from a website using ASP.NET and IIS read this post.

In order to do that I added a Boolean flag to the server cache for 10 minutes. When the users access a specific feature of the site it will check if the flag in the cache is set. If so the end user will be taken to a page that shows a “Batch Running” message (shown below using jQuery).   The “Batch Running” page will post back to the server every minute checking if the cache item exists. Once the cache item is gone the batch process page will redirect the user back to the feature that was offline.
if (CTX.Cache["BatchRunning"] == null) Response.Redirect("~/default.aspx")

The Javascript below clicks a button every minute to post back the page
var Timer = setInterval(function () { ClickButton() }, 60000);
function ClickButton() {
    document.getElementById("BtnPost").click();
}
The ZIP file below contains a HTML page and an ASPX page with the code discussed in this post.
BatchProcessingMessage.zip (3.3KB)

ASP.NET - Expire Cookie When User Closes the Browser

I had a need for Site A to communicate a value to Site B on the same domain. I wanted to do this through a cookie and if the user closed Site A the cookie would expire.  This can be done by not setting a expiration date on the cookie. 
//------------------------------------------------
// Site A - Create a cookie with no expiration  
//------------------------------------------------
private void SetCoookieValue()
{
  HttpContext CTX = HttpContext.Current;
  var CookieValue = 'TEST';
  
  var CookieName = "MY_COOKIE";
  HttpCookie MyCookie = new HttpCookie(CookieName);
  if (CTX.Request.Cookies[CookieName] != null) MyCookie = CTX.Request.Cookies[CookieName];
    
  MyCookie.Value = CTX.Server.UrlEncode(CookieValue);
    
  //No Expiration - it will expire when the user closes the browser
  //MyCookie.Expires = DateTime.Now.AddHours(8);
  CTX.Response.Cookies.Add(MyCookie);
}
    
//------------------------------------------------    
// Site B - Attempt to read the cookie in, 
// it should be gone after closing Site A
//------------------------------------------------  
private string GetCookieValue(string cookieName, string itemName)
{
    var CookieName = "MY_COOKIE";
    var CookieValue = string.empty;

    HttpCookie myCookie = Request.Cookies[CookieName];
    if (myCookie == null) return "No cookie found";

    //If you added a key vs. the value in the cookie
    //CookieValue = myCookie[itemName].ToString();

    //Get the value of the cookie 
    CookieValue = Page.Server.UrlDecode(myCookie.Value.ToString());
}