I have a project what I developed with Asp.Net MVC.I use view engine both forms and razor but razor pages (.cshtml) not working on IIS (IIS 7).While I check all settings (such as handler mapping, runAllManagedModulesForAllRequests,webpages:Enabled, webpages:Version) everything seems properly.Returning "500 Internal Server Error" as error while I inspect to error through fiddler but IIS log is appearing clean. What can be cause this error?
-
What exception is being thrown? If it's a .NET error, you should be getting a yellow-screen that gives you something useful. – Joe Enos Dec 09 '14 at 16:05
-
Also, check the Windows Event Log, especially the Application log. – John Saunders Dec 09 '14 at 16:07
-
Does not return any error specified exception, razor page rendered empty (as white page).I encountered this exception while inspecting though Fiddler. – Goran Zooferic Dec 09 '14 at 16:10
-
@JoeEnos: No, this is occurring once deployed (IIS 7). Though, the OP can enable this by temporarily adding `
` in the ` ` section of the Web.config. – Chris Pratt Dec 09 '14 at 16:10 -
I tried a couple solution and I'll write exception detail.Actually razor page worked properly it has broken suddenly. – Goran Zooferic Dec 09 '14 at 16:30
7 Answers
One possibility is the recently released Windows security update MS14-059.
Basically, that update completely uninstalls MVC 4.0.0.0 and replaces it with 4.0.0.1 on your server, and it has caused grief for many people with broken builds. The workaround is usually to add the relevant assemblyBinding redirects to Web.config, but there are other solutions - check here for details.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>

- 1
- 1

- 55,572
- 24
- 139
- 212
Problems consisted due to razor view engine version.I had to replace form page (.aspx) with existing pages.I have solved my problem but this isn't right way for solution.
Problem detail:
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'.

- 371
- 8
- 23
heres my cshtml that works fine, incorportaes razor and bootstrap
@using System.Data
@model IEnumerable<CampRoll.Models.Camp>
<div class="container">
<h2>@ViewBag.PageTitle</h2>
<p>
@Html.ActionLink("Create New", "Create", null, new { @class = "btn btn-success" })
</p>
<div class="row">
<div class="col-xs-8">
<table id='campsTable' class="table table-condensed table-striped">
<tr>
<th>
@Html.DisplayNameFor(model => model.Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Leader)
</th>
<th>
@*@Html.ActionLink("StartDate",null,new{sortOrder=@ViewBag.dateOrder},
new{@class="btn btn-info btn-xs"})*@
<a class="btn btn-xs btn-info" href="@Url.Action("Index", new { sortOrder = @ViewBag.dateOrder })">
@if (ViewBag.dateOrder == "ascDate")
{
<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
}
else if (ViewBag.dateOrder == "descDate")
{
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
}
StartDate
</a>
</th>
<th><a class="btn btn-xs btn-info" href="@Url.Action("Index", new { sortOrder = @ViewBag.numberOrder })">
@if (ViewBag.numberOrder == "descNumber")
{
<span class="glyphicon glyphicon-arrow-up" aria-hidden="true"></span>
}
else if (ViewBag.numberOrder == "ascNumber")
{
<span class="glyphicon glyphicon-arrow-down" aria-hidden="true"></span>
}
Number
</a></th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
<span class="btn btn-xs btn-warning"
onclick="showChildren('@item.CampId')">@Html.DisplayFor(modelItem => item.Title)</span>
</td>
<td>
<span class="btn btn-xs btn-danger" onclick="showLeader('@item.LeaderId')">
@Html.DisplayFor(modelItem => item.Leader.FirstName)
</span>
</td>
<td>
@Html.DisplayFor(modelItem => item.StartDate)
</td>
<td>
@if (item.Children.Count == 0)
{
<p style="margin: 0px">None</p>
}
else
{
@Html.DisplayFor(modelItem => item.Children.Count)
}
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.CampId }, new { @class = "btn btn-info btn-xs" })
@Html.ActionLink("Details", "Details", new { id = item.CampId }, new { @class = "btn btn-info btn-xs" })
@Html.ActionLink("Delete", "Delete", new { id = item.CampId }, new { @class = "btn btn-danger btn-xs" })
</td>
</tr>
}
</table>
</div>
<div class="col-xs-4">
<div id="Detail"></div>
<div>
<form id="CreateChild" hidden="">
<div class="form-group" style="margin-top: 10px">
<input type="hidden" name="campId">
<input type="submit" value="Add" class="btn btn-xs btn-success" style="margin-top: -5px;" />
<input type="text" name="name"><span> to Camp</span>
</div>
</form>
<form id="EditChild" hidden="">
<div class="form-group" style="margin-top: 10px">
<input type="hidden" name="campId"><input type="hidden" name="childId">
<input type="hidden" name="sex">
<input type="submit" value="Save" class="btn btn-xs btn-success" style="margin-top: -5px;" />
<input type="button" onclick="$('#EditChild').hide(); $('#CreateChild').show();" value="Cancel" class="btn btn-xs btn-warning" style="margin-top: -5px;" />
<input type="text" name="name" value="">
<div style="margin:-5px 5px" class='badge alert-info'><input type="radio" name="male" value="">M
<input type="radio" name="female" value="">F</div>
</div>
</form>
</div>
</div>
<!-- End Details -->
</div>
@section scripts
{
<script>
$(function() { // ready event
toastr.info('Welcome to Camp Roll');
// Handle toggle of male/female
$('#EditChild :input[name="male"]').click(function() {
$('#EditChild :input[name="female"]').prop('checked', false);
});
$('#EditChild :input[name="female"]').click(function() {
$('#EditChild :input[name="male"]').prop('checked', false);
});
@if (Model.Any())
{
// On display show the children in the first camp
<text>
showChildren(@Model.First().CampId);
</text>
}
});
// POSTback of creating a new child
$('#CreateChild').submit(function() {
if ($(this).find('input[name="name"]').val()!="") {
$.ajax({
url: '@Url.Action("CreateChild")',
type: "POST",
data: $(this).serialize(), // serialize the input controls for this form '#CreateChild'
success: function() {
showChildren($('form').find('input[name="campId"]').val()); // refresh the table of children
toastr.info($('form').find('input[name="name"]').val() + ' Added'); // toast
$('form').find('input[name="name"]').val(""); // zero out the add child box
}
});
}
return false;
});
// Display leader of the camp
function showLeader(leaderId) {
// When Leader name clicked, invoke Controler action method to return partial view and ajax it into place
@*$('#Detail').load('@Url.Action("LeaderById")' + '?id=' + leaderId).fadeIn(1000);*@
$.ajax({
url: '@Url.Action("LeaderById")',
data: { id: leaderId },
success: function(data) {
$('#Detail').hide();
$('#CreateChild').hide();
$('#Detail').html(data);
$('#Detail').fadeIn(1000);
},
error: function() {
$('#Detail').html("<h3>Couldn't find a leader</h3>");
}
}
);
}
// ajax Display of Children in the selected camp
function showChildren(campId) {
// When Leader name clicked, invoke Controler action method to return partial view and ajax it into place
$.ajax({
type: "GET",
url: '@Url.Action("ChildrenById")',
data: { id: campId },
success: function(data) {
$('#Detail').hide();
$('#CreateChild').hide();
$('#Detail').html(data);
$('#Detail').fadeIn("slow");
$('#CreateChild').find('input[name="campId"]').val(campId); // set campId for the Create Child form
$('#CreateChild').find('input[name="name"]').val("");
$('#CreateChild').fadeIn("slow");
},
error: function(data) {
$('#Detail').html('<h3>Error in retrieval</h3>');
}
});
}
function showEditChild(campId, childId, childName, sex) {
$('#EditChild').slideDown("fast");
$('#EditChild').show();
$('#CreateChild').hide();
$('#EditChild :input[name="childId"]').val(childId);
$('#EditChild :input[name="campId"]').val(campId);
$('#EditChild :input[name="name"]').val(childName);
if (sex == 'Male') {
$('#EditChild :input[name="male"]').prop('checked', true);
$('#EditChild :input[name="female"]').prop('checked', false);
} else {
$('#EditChild :input[name="female"]').prop('checked', true);
$('#EditChild :input[name="male"]').prop('checked', false);
}
}
$('#EditChild').submit(function() {
if ($('#EditChild :input[name="male"]').prop('checked') == true) {
$('#EditChild :input[name="sex"]').val('male');
} else {
$('#EditChild :input[name="sex"]').val('female');
}
$.ajax({
url: '@Url.Action("UpdateChild")',
type: "POST",
data: $(this).serialize(),
success: function() {
$('#EditChild').hide();
showChildren($('#EditChild :input[name="campId"]').val()); // refresh the table of children
toastr.info($('#EditChild :input[name="name"]').val() + ' Updated');
},
error: function(data) {
$('#Detail').html('<h3>Could not update Child record</h3>');
}
});
return false;
});
function deleteChild(childId, campId) {
$.ajax({
type: "POST",
url: '@Url.Action("DeleteChild")',
data: { id: childId, campId: campId },
success: function(data) {
$('#Detail').hide();
$('#CreateChild').hide();
$('#Detail').html(data);
$('#Detail').fadeIn("slow");
$('#CreateChild').find('input[name="campId"]').val(campId); // set campId for the Create Child form
$('#CreateChild').find('input[name="name"]').val("");
$('#CreateChild').fadeIn("slow");
},
error: function(data) {
$('#Detail').html('<h3>Error in retrieval</h3>');
}
});
}
</script>
}

- 11
- 2
delete
@model CampRoll.Models.Camp
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<h4>Confirm deletion of @Model.Title</h4>
</div>
</div>
<div class="panel-body">
<fieldset>
<legend>Details</legend>
<div>
@Html.DisplayFor(model => model.Title) starting
@Html.DisplayFor(model => model.StartDate)
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<input type="submit" value="Delete" class="btn btn-danger" />
}
</div>
</fieldset>
</div>
<div class="panel-footer">
@Html.ActionLink("Back to List", "Index", null, new { @class = "btn btn-success" })
</div>

- 11
- 2
create @using System.Web.UI.WebControls @using CA2.Models @model CA2.Models.Movie
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<div class="lead">Create Movie</div>
</div>
<div class="panel-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<div class="row">
<div class="form-group col-xs-4">
@Html.LabelFor(model => model.MovieTitle)
@Html.TextBoxFor(model => model.MovieTitle, new { @class = "form-control" })
@*@Html.ValidationMessageFor(model => model.MovieTitle)*@
</div>
<div class="form-group col-xs-4">
@Html.LabelFor(model => model.Director)
@*@Html.TextBoxFor(model => model.StartDate,new { @class = "form-control" })*@
<div class='input-group' id='datetimepicker1'>
<input type='text' name="MovieTitle" />
<span class="input-group-addon"></span>
</div>
@*@Html.ValidationMessageFor(model => model.Director)*@
</div>
@*<div class="col-xs-4">
@Html.LabelFor(model => model.Actors)
@Html.DropDownList("Actors",
new SelectList(ViewBag.Actors, "MovieTitle"),
new { @class = "form-control" })
</div>*@
</div>
<div>
<button class="btn btn-success"><span class="glyphicon glyphicon-plus"></span>Create</button>
</div>
}
</div>
<div class="panel-footer">
<a class="btn btn-danger" href="@Url.Action("Index")">
<span class="glyphicon glyphicon-home"></span> Back to List
</a>
@*@Html.ActionLink("Back to List", "Index",null,new {@class="btn btn-xs btn-info"})*@
</div>
</div>

- 11
- 2
Edit
@using CA2.Models
@model CA2.Models.Movie
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<h4>Edit @Model</h4>
</div>
</div>
<div class="panel-body">
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Movie</legend>
@Html.HiddenFor(model => model.Id)
<div class="row">
<div class="form-group col-xs-4">
@Html.LabelFor(model => model.MovieTitle)
@Html.TextBoxFor(model => model.MovieTitle,
new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.MovieTitle)
</div>
<div class="form-group col-xs-4">
@*@Html.LabelFor(model => model.Id)
<div class='input-group date' id='datetimepicker1'>
<input type='text' name="StartDate" value="@Model.Director" class="form-control" data-date-format="DD/MM/YYYY" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span></span>
</div>*@
@*@Html.ValidationMessageFor(model => model.Director)*@
</div>
<div class="form-group col-xs-4">
@*@Html.LabelFor(model => model.Actors)
@Html.DropDownList("Actors", new SelectList(ViewBag.Actors, "Actors", Model.Actors),
new { @class = "form-control" })*@
</div>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary"
value="Save" />
</div>
</fieldset>
}
</div>
<div class="panel-footer">
@Html.ActionLink("Back to List", "Index", null, new { @class = "btn btn-success" })
</div>

- 11
- 2