HTTP Error 403.14 – Forbidden The Web server is configured to not list the contents


While hosting the asp.net or asp.net MVC application on IIS, you might have faced this exception on browser
“HTTP Error 403.14 – Forbidden The Web server is configured to not list the contents”

To fix this issue, you might have to check the two possible setting in IIS

First: Make sure that the .NET Framework version value is v4.0.

iis_error1

For this you have to do like this

1. Open the Run dialog, type inetmgr and then click OK. This opens the IIS Manager.

2. In the left tree-view, locate the Sites node and find the Default Web Site node under it (or the name of the site where the error message appears).

3 Right-click the node and select Manage web site -> Advanced settings…. Note the name of the value Application pool. Close this dialog.

4. In the treeview to the left, locate and select the node Application pools.

5. In the list to the right, locate the Application pool with the same name as the one you noted in the web site settings. Right-click it and select Advanced settings

6. Make sure that the .NET Framework version value is v4.0. Click OK.


Second: Asp.net is not registered on Server

For this you have to go to
>>Visual Studio
>> Then Visual Studio Tool >> Visual Studio Command Prompt

>> Then Go to the given path C:\Windows\Microsoft.NET\Framework64\v4.0.30319
>> Then run the aspnet_regiis.exe -ir

iis_error

How to implement jquery accordion in asp.net MVC


AccordianJqery

It is very straight forward to implement jquery accordion in asp.net MVC. If we have to implement any jquery UI widgets in asp.net mvc  there will be no need to do any extra work. This is the cool features of asp.net MVC.

Lets check with one simple  asp.net MVC 4  application.

Step1: Create one blank asp.net mvc  application.

Step2: Download the Jquery and Jquery UI libray fron Nuget Package Manager in the application.

Step 3: Create the Home controller  like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication8.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }

    }
}



Step 4: Create the Index view and implement Jquery and style sheet like this Code snippet


@{
    ViewBag.Title = "Index";
}

<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<script src="~/Scripts/jquery-ui-1.11.2.min.js"></script>
<link href="~/Content/themes/base/all.css" rel="stylesheet" />
<link href="~/Content/themes/base/accordion.css" rel="stylesheet" />
<link href="~/Content/demos.css" rel="stylesheet" />

<script type="text/javascript">
    $(function () {
        $("#accordion").accordion();
    });
</script>

<div class="demo">
<div id="accordion">
  <h3>This is the Title1</h3>
  <div>
    <p>
    Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
    ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
    amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
    odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
    </p>
  </div>
  <h3>This is the Title2</h3>
  <div>
    <p>
    Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
    purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
    velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
    suscipit faucibus urna.
    </p>
  </div>
  
</div>

</div>


Summary: Here i donot have done any exatra work to implement this functionality so asp.net MVC is very user friedly with Jquery UI Library. This is one of the good features of asp.net MVC.

How to implement Insert Update Delete functionality in Single View?


EntryScreen

So many People like to do Insert/Update/Delete in single View i.e. similar to asp.net. But asp.net MVC default it does not support this approach. We can achieve this functionality like this

Step 1:
Create the blank application like this

InitialPage

Empty

Step 2: Create the database table like this

Database

Step 3: In model layer, create the model using EF database first approach like this

EmpModel

Step 4: Now create a blank Emp controller like this

EmpController

Step 5: Add a class i.e HttpParamActionAttribute in solution like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
 
namespace EmpDemoInMVC
{
    public class HttpParamActionAttribute : ActionNameSelectorAttribute
    {
        public override bool IsValidName(ControllerContext controllerContext, string actionName, MethodInfo methodInfo)
        {
            if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
                return true;
 
            var request = controllerContext.RequestContext.HttpContext.Request;
            return request[methodInfo.Name] != null;
        }
    }
}

Note: We are writing this class to fire the multiple Submit button events from single view.

Step 6: Write the Action Method in Controller for Insert/Update/Delete and fetch functionalities like this


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EmpDemoInMVC.Models;
using System.Data.Entity;
 
namespace EmpDemoInMVC.Controllers
{
    public class EmpController : Controller
    {
 
        EmpEntities db = new EmpEntities();
        
        //
        // GET: /Emp/
        public ActionResult Index(int? id)
        {
            ViewBag.Operation = id;
            ViewBag.Name = db.tblEmps.ToList();
            tblEmp objEmp = db.tblEmps.Find(id);
            return View(objEmp);
        }
 
        [HttpPost]
        [HttpParamAction]
        [ValidateAntiForgeryToken]
        public ActionResult Create(tblEmp objEmp) 
        {
            if (ModelState.IsValid)
            {
                db.tblEmps.Add(objEmp);
                db.SaveChanges();
            }
            return RedirectToAction("Index");
        }
 
        [HttpPost]
        [HttpParamAction]
        [ValidateAntiForgeryToken]
        public ActionResult Update(tblEmp objEmp)
        {
            if (ModelState.IsValid)
            {
                db.Entry(objEmp).State = EntityState.Modified;
                db.SaveChanges();
            }
            return RedirectToAction("Index", new { id = 0 });
        }
 
        public ActionResult Delete(int id)
        {
            tblEmp objEmp = db.tblEmps.Find(id);
            db.tblEmps.Remove(objEmp);
            db.SaveChanges();
            return RedirectToAction("Index", new { id = 0 });
        }
	}
}

Step 7: Create the Empty View from controller like this

View

Step 8: Now write the html code as per as our requirement like this

@model EmpDemoInMVC.Models.tblEmp
 
@{
    ViewBag.Title = "Index";
}
 
<h2>Index</h2>
 
@using (Html.BeginForm()) 
{
    // This is For EmpDetail in Grid
        <fieldset>
            <legend><b>Emp Details</b></legend>
            <table border="1" cellpadding="10">
                <tr>
                    <th>
                        @Html.DisplayNameFor(model => model.Name)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Address)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.EmailId)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.MobileNo)
                    </th>
                    <th>
                        @Html.DisplayNameFor(model => model.Country)
                    </th>
                    <th>
                        Action
                    </th>
                </tr>
 
                @foreach (var item in (IEnumerable<EmpDemoInMVC.Models.tblEmp>)ViewBag.Name)
                {
                    <tr>
                        <td>
                            @Html.DisplayFor(modelItem => item.Name)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Address)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.EmailId)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.MobileNo)
                        </td>
                        <td>
                            @Html.DisplayFor(modelItem => item.Country)
                        </td>
                        <td>
                            @Html.ActionLink("Edit", "Index", new { id = item.Id }) |
                             @Html.ActionLink("Delete", "Delete",new { id = item.Id },new { onclick = "return confirm('Are you sure you wish to delete this article?');" })
                        </td>
                    </tr>
                }
 
            </table>
      </fieldset>
    
    // This is for the Emp Entry Screen
    @Html.AntiForgeryToken()
    <div class="form-horizontal">
       
        @Html.ValidationSummary(true)
 
        <fieldset>
            <legend> <b>Entry Screen</b></legend>
 
            <div class="form-group">
                @Html.LabelFor(model => model.Name, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name)
                    @Html.ValidationMessageFor(model => model.Name)
                </div>
            </div>
 
            <div class="form-group">
                @Html.LabelFor(model => model.Address, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Address)
                    @Html.ValidationMessageFor(model => model.Address)
                </div>
            </div>
 
            <div class="form-group">
                @Html.LabelFor(model => model.EmailId, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.EmailId)
                    @Html.ValidationMessageFor(model => model.EmailId)
                </div>
            </div>
 
            <div class="form-group">
                @Html.LabelFor(model => model.MobileNo, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.MobileNo)
                    @Html.ValidationMessageFor(model => model.MobileNo)
                </div>
            </div>
 
            <div class="form-group">
                @Html.LabelFor(model => model.Country, new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Country)
                    @Html.ValidationMessageFor(model => model.Country)
                </div>
            </div>
            <div class="form-group">
                <p>
                    <input type="submit" value="Create" name="Create"
                           style=@((ViewBag.Operation != null && Convert.ToInt32(ViewBag.Operation) > 0) ? "display:none" : "display:block") />
                    <input type="submit" value="Update" name="Update"
                           style=@((ViewBag.Operation != null && Convert.ToInt32(ViewBag.Operation) > 0) ? "display:block" : "display:none") />
                </p>
            </div>
            </fieldset>
 
</div>
}
 

Summary:

In this article we show that we are using only one view for doing Insert/Update/Delete and Fetch function. If you like to implement entry screen similar to asp.net style you can use this approach.