Dave's Technophorical Times

A blog about Microsoft's Technologies!
SharePoint :: MVC :: ASP.NET :: IIS :: SQL Server :: Visual Studio :: MS Access

Use $PSVersionTable.PSVersion to determine the engine version. If the variable does not exist, it is safe to assume the engine is version 1.0.

Note that $Host.Version and (Get-Host).Version are not reliable - they reflect the version of the host only, not the engine. PowerGUI, PowerShellPLUS, etc. are all hosting applications, and they will set the host's version to reflect their product version, which is entirely correct.

Note: This issue is also related to -> An exception occurred when trying to issue security token: The HTTP service located at http://localhost:32843/SecurityTokenServiceApplication/securitytoken.svc/actas is too busy

Recently I had a client where their virtual environment failed due to a hardware failure. After they brought everything up and fixed the hardware issue SharePoint was not working. Specifically SharePoint Central Administration, Security Token Service App Pool, the main SharePoint web application and My Site web application would not start.

Based on numerous blog posts and my experience with IIS I started down the typical fixes:

  • Manually start the individual web application
  • Make sure the Identity on the web application was correct and the right credentials were in place
  • Even running the SharePoint Configuration Wizard to fix any issues

After each one of these I would try hitting SharePoint Central Administration and would get a Server Not Available 503 error then go back into IIS and the web application would be stopped.

I then started looking into the ULS and Event Viewer to dig a little deeper.I started to see a pattern of something did not have permissions across these multiple web applications. Finally I searched the webs on a Application Event ID error of 5059 that basically said that “Windows Process Activation Service (WAS) encountered a failure when it started a worker process to serve the application pool.” Luckily this error pointed me to the follow SharePoint Forum post that got me on the right direction.

In essence there was a specific permission needed by SharePoint to allow the Identity for the web application to work. The local security policy of “log on as a batch job” user permission needs to be in place. My theory is when the domain went down a older version of the domain policy was pushed out and removed those permissions.

I ended up going into Group Policy Management console and had to find the policy where this was set. In this case the Domain Default Policy. The Log on as a batch job setting is found in Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > User Rights Assignment > Log on as a batch job. Add the SP Admin accounts to the list and also add the IIS_IUSRS local Group as ith should contain the accounts for all the SP Application Pools. Afterwards I did a gpupdate /force and restarted the SharePoint server and everything was happy.

Hope this helps somebody else!

Thanks to Don Donais http://talesfromitside.wordpress.com/2011/12/06/log-on-as-a-batch-job-permissions-removed/

Here are FOUR fantastic tutorials on MVC5 Identity i.e. Forms Based Authentication (FBA). It's not like the old version when you had to create an ASPNETDB database! The .NET 4.5 Framework has a lot of built in code so these well written aticles help show this.





Excellent work Jon Atten!


I want to use email (or a dot in the username!) as the username with Microsoft.AspNet.Identity in MVC 5 application. But when I do I get the following error:

User name ... is invalid, can only contain letters or digits.


In the AccountController constructor that takes a userManager as a parameter add the following code:

UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager)
 { AllowOnlyAlphanumericUserNames = false };

I had this issue a few times already, so I will write down the procedure I follow also as a reminder for myself:

  1. Replace all of the old solution name with the new one.
  2. Navigate to Properties under each project and change the Assembly Name and Default Namespace fields to new solution name.
  3. Go to solution folder and rename all project folders with the new solution name.
  4. Remove all files under bin and obj folders.
  5. Solution will not be able to load projects. Remove all projects and add them again.
  6. Re-build the project.

Source: http://stackoverflow.com/questions/21701297/error-when-renaming-asp-net-mvc-5-applciation

When developing your Excel or Access application, it’s not uncommon to need to capture your user’s domain/username for one reason or another. A user’s domain/username combination is the traditional unique identifier for a user - often captured by programmers to do things in like:

  • Help manage user login and permissions
  • Create a history of who used the application
  • Capture the name of each user who made the changes to data
  • Personalize outputs and program messages for users

There are literally half a dozen ways to capture a user’s domain name and user name. In this post, I’ll give you a very easy method using the Environ function.

Environ stands for Environment, and refers to environment variables in an operating system. Environment variables are specially named aliases for specific system properties, exposed as a kind of shortcut for system administrators and programmers.

Although majority of these Environment variables are useless to your average Excel/Access developer. There are a few that can prove to be useful. Two of these are the UserDomain and UserName variables. We can use these to capture a user’s Domain\UserName.

To demonstrate this, I’ve entered the following function into a standard module. You can call this from a form or query!

Function getReturnUName()
       getReturnUName = Environ(“UserDomain”) & “\” & Environ(“Username”)
End Function


  • Sub EnvironListing()
  •  Dim I As Integer
  •  I = 1
  •   Do Until environ(I) = ""
  •     Debug.Print environ(I)
  •     I = I + 1
  •   Loop
  • End Sub

  • Sometimes you need to refresh the local cache in SQL Server when writting code to remove that annoying red squiggly line.

    Edit -> Intellisense - Refresh Local Cache


    Usually you will see this if the user does not have rights to the SharePoint config database, or if the .NET 4.X framework is not installed.

    All the Best

    Here is a script that I wrote for backing up some very important files to an off-site ftp location. It backs up only files that are new OR have changed in the last 24 hours. That number of days could be a parameter based on when the backup last ran, however this is the base code that you can start using right away. Just add it to a Task Schedule that runs one a day.

    # ==============================================================================================
    #Set the Date/Time
    # ==============================================================================================
    $BackUpdateTime  = (Get-Date).Year.ToString()
    $BackUpdateTime += (Get-Date).Month.ToString()
    $BackUpdateTime += (Get-Date).Day.ToString()
    $BackUpdateTime += (Get-Date).Hour.ToString()
    $BackUpdateTime += (Get-Date).Minute.ToString()
    $BackUpdateTime += (Get-Date).Second.ToString()
    $today = (Get-Date -Format yyyy-MM-dd)

    try {
     $ftp = "ftp://ftp.mysite.ca/"
     $user = "ftpuser"
     $pass = "ftppassword" 
     $webclient = New-Object System.Net.WebClient
     $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass) 

     #we specify the directory where all files that we want to upload 
     #Write-Host $LogFile
     "From:"+$Dir+" (on server01) To:"+$ftp | Out-File $LogFile -Append
     "Start: "+(Get-Date) | Out-File $LogFile -Append

     $files = @(Get-ChildItem -Path  $Dir -Recurse | ?{ !$_.PSIsContainer } |Where-Object { $_.lastwritetime -gt (get-date).AddDays(-1)} | Select-Object -ExpandProperty FullName )
     foreach($item in $files)
         if($item -ne $null)
       $uri = New-Object System.Uri($ftp+$item.Substring(3))
       $webclient.UploadFile($uri, $item)
       #Write-Host (Get-Date)$item
       "$(Get-Date): "+$item | Out-File $LogFile -Append

     "End:"+(Get-Date) | Out-File $LogFile -Append
     $msg = new-object Net.Mail.MailMessage
     # Edit the From Address as per your environment. 
     $msg.From = "Backup (server01) <my.email@mysite.ca>"

     # Edit the mail address to which the Notification should be sent. 

     # Subject for the notification email. The + “$today” part will add the date in the subject. 
     $msg.Subject = "Backup was Successful for " + "$today"

     # Body or the notification email. The + “$today” part will add the date in the subject. 
     $msg.Body = "Backup was Successful for " + $today + "`r`n`r`n" 
     $att = new-object Net.Mail.Attachment($LogFile)
     # IP address of your SMTP server.
     $smtpServer = "smtp.mysite.ca" 
     $smtp = new-object Net.Mail.SmtpClient($smtpServer) 

    Catch { 
     $ErrorMessage = $_.Exception.Message 

     # Configure the below parameters as per the above. 
     $msg = new-object Net.Mail.MailMessage
     $msg.From = "Backup (server01) <my.email@mysite.ca>" 
     $msg.Subject = "Backup Job failed on " + "$today" 
     $msg.Body = "Job failed on " + "$today and the reason for failure was $ErrorMessage." 
     $att = new-object Net.Mail.Attachment($LogFile)
     $smtpServer = "smtp.mysite.ca" 
     $smtp = new-object Net.Mail.SmtpClient($smtpServer) 

    The files that you attach to an email become locked until the instance of Powershell you are running has exited completely. So if you run a script through Powershell ISE that attaches a file to an email, that file will remain locked until you exit Powershell ISE.

    If the file is locked by Powershell, you will get an error/warning message similar to the following if you try to modify it in any way;

    The process cannot access the file 'c:\filename.txt' because it is being used by another process

    By using the following command, you can ensure that Powershell 'disposes' of the email message once it has been sent and does not continue to 'lock' any files you attach and send via email;


    Note: this is assuming that $MailMessage = New-Object system.net.mail.mailmessage

    The Blogger

    Dave Stuart I'm a Developer with a passion for coding. I enjoy the challengers that come with the job! SharePoint is one of my expert areas along with .NET Web Development with MVC and good old MS Access VBA coding. I Blog so that I can remember how I did that way back when; PLUS all this stuff is searchable! I constantly study and run my own business, Dafran Inc. I have passed 22 Microsoft Exams since 1998 when I first jumped on the treadmill of knowledge. I hope that you enjoy this Blog as much as I enjoy updating it. All the very best from Calgary, Alberta, Canada. contact me at linkedin @ dafran.ca


    <<  May 2022  >>

    View posts in large calendar

    Sign in