0

Recently I came across an issue with an Index view. The page displays as nonsense data as seen in this image link, Result of UserManager.Users.ToListAsync(). This just start happening but not sure why. Any help on this would be amazing!

The code is pretty simple:

public virtual async Task<ActionResult> Index()
{
    return View(await UserManager.Users.ToListAsync());
}

The View

@model IEnumerable<SafeWare.Models.Identity.ApplicationUser>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>

</p>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.UserName)
        </th>
        <th>

        </th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.UserName)
            </td>
            <td>
                @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
                @Html.ActionLink("Details", "Details", new { id = item.Id }) |
                @Html.ActionLink("Delete", "Delete", new { id = item.Id })
            </td>
        </tr>
    }

</table>

OnActionExecuting

protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
    bool allowCompression = true;
    //bool.TryParse(ConfigurationManager.AppSettings["Compression"], out allowCompression);

    if (allowCompression)
    {
        HttpRequestBase request = filterContext.HttpContext.Request;

        string acceptEncoding = request.Headers["Accept-Encoding"];

        if (string.IsNullOrEmpty(acceptEncoding)) return;

        acceptEncoding = acceptEncoding.ToUpperInvariant();

        HttpResponseBase response = filterContext.HttpContext.Response;

        if (acceptEncoding.Contains("GZIP"))
        {
            response.AppendHeader("Content-encoding", "gzip");
            response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
        }
        else if (acceptEncoding.Contains("DEFLATE"))
        {
            response.AppendHeader("Content-encoding", "deflate");
            response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
        }
    }
    base.OnActionExecuting(filterContext);
}
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
chrisdyck
  • 27
  • 1
  • 8
  • 2
    Looks like an text encoding issue. What does your view look like? – Chris Pratt Apr 07 '17 at 16:28
  • Yeah, this happens when you try to stuff double byte characters into an ASCII string. – Fran Apr 07 '17 at 16:42
  • Thanks guys, I've added the view code. It's pretty plain Jane vanilla view code – chrisdyck Apr 07 '17 at 16:50
  • Might also be that you have set up Gzip compression but aren't using the correct HTTP headers. See http://stackoverflow.com/q/3960707/215552 or http://stackoverflow.com/q/5876930/215552 for instance. – Heretic Monkey Apr 07 '17 at 16:55
  • @MikeMcCaughan ah yes! That could be it. I'll look into that. I've added my OnActionExecuting – chrisdyck Apr 07 '17 at 17:05
  • I would think my whole application would be failing though. This is from a BaseController that executes the OnActionExecuting – chrisdyck Apr 07 '17 at 17:10

0 Answers0