Adding Build Configuratior in Asp.Net

Beside “Debug” there is a dropdown, click and select “Configuration Manager”. In “Active Solution Configuration” select “New” then add a name like “Testing” and “Select copy settings from” preferrably copy settings from Release.

Right click “web.config” and select “Add Config Transform”. This will create Web.Testing.config.

Securing Configuration Settings

    <add key="webpages:Version" value="" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />

Create another config file like AppSettings.config and in web.config > appSettings, add configSource attribute and specify the file

<appSettings configSource="AppSettings.config"></appSettings>

This is useful in public repositories and other scenarious where you don’t want to share your other credentials but to specific people only.
Exclude the AppSettings.config from repository


@Html.TextAreaFor(j => j.JobDescription, new { @class = "form-control", @rows = "6", @placeholder = "Enter Job Description" })
        <small class="color-white-mute">Formatting Options: ##heading *italic* **bold** * bulleted list</small>
        <span id="showdown-container">
            <span id="showdown-preview">Preview</span>


$("#JobDescription").keyup(function () {
    var txtBox = $(this);
function showdownConvert(txtBox) {
    var converter = new showdown.Converter({ headerLevelStart: 2 });

    if (txtBox.val()=="") {


Increasing IIS Upload Limit

When uploading file to IIS greater than default will lead to
Exception Details: System.Web.HttpException: Maximum request length exceeded.

To solve this problem, we need specify our upload limit the server is allowed to accept say 5MB (1024×5000)
In Web.config > system.web add
<httpRuntime maxRequestLength="5120000" executionTimeout="3600" />

In Web.config > system.webServer
        <requestLimits maxAllowedContentLength="5120000" />

Note: maxRequestLength and maxAllowedContentLength must match

Customizing PagedList.Mvc

page => Url.Action("Jobs",
new { controller = "Company", area = "Admin", page, sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }),
new PagedListRenderOptions
LinkToFirstPageFormat = "<<",
LinkToLastPageFormat = ">>",
LinkToNextPageFormat = "",
LinkToPreviousPageFormat = "",
UlElementClasses = new[] { "pagination","pagination-theme" }

More info about PagedList.Mvc

Entity Framework 6 Transaction

using (var dbContextTransaction = dbContext.Database.BeginTransaction())
var job = new Job{Name = "Name"}

var companyJobs = new CompanyJob{Name="Name",JobId = Job.Id};
catch (Exception)

Another method is using scope, pass TransactionScopeAsyncFlowOption.Enabled to TransactionScope() constructor to allow async saving method

using (var transactionScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
var job = new Job{Name = "Name"}

var category = dbContext.Categories.Find(2);


More ways here

Dealing with One-to-Many Relationship in Fluent API

For example, a Company has many Jobs, in Company Configuration add
HasMany(c => c.Jobs)
.WithRequired(j => j.Company)
.HasForeignKey(j => j.CompanyId);

Without the above configuration, Company navigation property of Job will not work.

While in Job Configuration
HasRequired(j => j.Company)
.WithMany(c => c.Jobs)
.HasForeignKey(j => j.CompanyId);

Add the 2 configuration so that their navigational properties will work.

Adding Glimpse to ASP.Net

Glipse is a tool to monitor the performance of web app.

install-package glimpse.mvc5
Install-Package Glimpse.EF5

If you encounter this problem
Unable to cast object of type 'Glimpse.Ado.AlternateType.GlimpseDbConnection' to type 'System.Data.SqlClient.SqlConnection'.
Uninstall Glimpse.EF5 and install
Install-Package Glimpse.EF6
You can view Glimpse endpoint in /glimpse.axd

Could Not Find Driver in Ubuntu CLI

Note, the PHP version of Apache and Terminal could be different.
Web phpinfo() shows

Loaded Configuration File /etc/php5/apache2/php.ini
PDO drivers | mysql, sqlite

Checking on the terminal

$ php -i |grep php\.ini
Configuration File (php.ini) Path => /etc/php/5.6/cli
Loaded Configuration File => /etc/php/5.6/cli/php.ini

Checking for drivers
$ php -i|grep PDO
PDO support => enabled
PDO drivers =>

As we see we have no drivers

Ubuntu 14.04.3 LTS
sudo apt-get update
sudo apt-get install php5.6-fpm php5.6-mysql
$ php -i|grep PDO
PDO support => enabled
PDO drivers => mysql
PDO Driver for MySQL => enabled

Installing PHP 7 with Ubuntu

To fix “Could Not Find Driver” error
Ubuntu 16.04.1 LTS
sudo apt-get update;
sudo apt-get install php7.0-fpm php7.0-mysql