Cannot connect to SQL DB from IIS, connection works from IISExpress

Stackoverflow question/answer: http://stackoverflow.com/questions/20723623/application-cannot-open-sql-connection-when-on-iis

You can either give permission to the app pool from within SQL Server.

Or create a SQL Server user/pass, update the connection string to use User/Pass instead of Integrated Security

Setting up SSL with IIS for development and testing of ASP.NET applications

Note: this will potentially solve the issue when Visual Studio shows the following error upon trying to debug: “Unable to debug the web server… An error occurred on a send.”

The problem can be solved by re-creating and adding a SSL cert to the port 443 binding of the default web application.

 

Follow the following steps:

From IIS, under the local server, open “Server Certificates”. Use an existing cert or create a self-signed cert, give it a name.

Select the Web application(not a virtual directory) that you want to use. Edit the bindings, add a binding for https port 443 and select the certificate you created previously and then save.

Note: when running applications off an existing web application in IIS, make sure to create virtual directories for each app if they are not available, you can do so by going to the project’s properties, under “Using local IIS server”, next to the URL of the app click the button “Create virtual directory”

Add code behind to SharePoint 2013 master page

One way is to add delegate control to master page. Follow the article: http://www.sharepointpals.com/post/Step-by-step-procedures-to-create-a-delegate-control-in-SharePoint-2010

However for some reason, it’s required to set ControlSrc to “~/_ControlTemplates/15/…” or else the control won’t be used.

C# String problems

When retrieving HTML or string content from some editors such as SharePoint editor, the editor may insert zero-width or control characters in the content that can cause problem methods like string.IndexOf, string.Compare, string.Replace etc.

If the application only uses English language, it’s possible to strip all control characters from the data before doing other string operations.

Use the Regex to do so

data = Regex.Replace(data, @”[^x20-x7F]”, “”);

This line will remove all characters that are not in the range 0x20 to 0x7F in the ASCII table.

Then proceed to do string operations as per normal.

Read DateTime data from Excel file using C#

Excel files are very tricky to deal with, sometimes it returns double value, sometimes just plain string.

The example processes values read by EPPlus, might be useful in other situations, too.

public DateTime GetDate(object valFromExcel)
{
if(valFromExcel is DateTime) return valFromExcel;
if(valFromExcel is double) return DateTime.FromOADate((double)valFromExcel);
return Convert.ToDateTime(valFromExcel);
}