ASP.NET Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/technology/asp-net-performance/high-performance-web-applications-asp-net/ Production Grade Technical Solutions | Data Encryption and Public Cloud Expert Tue, 25 May 2021 00:59:09 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.1 https://www.anujvarma.com/wp-content/uploads/anujtech.png ASP.NET Archives - Anuj Varma, Hands-On Technology Architect, Clean Air Activist https://www.anujvarma.com/category/technology/asp-net-performance/high-performance-web-applications-asp-net/ 32 32 The framework microsoft.aspnetcore.app version 3.1.0 was not found https://www.anujvarma.com/the-framework-microsoft-aspnetcore-app-version-3-1-0-was-not-found/ https://www.anujvarma.com/the-framework-microsoft-aspnetcore-app-version-3-1-0-was-not-found/#respond Mon, 24 May 2021 23:45:46 +0000 https://www.anujvarma.com/?p=8303 If you see this error in VS Code, you are missing the aspnetcore runtime (even though you may have installed the larger .net core runtime). Basically, .net core is not […]

The post The framework microsoft.aspnetcore.app version 3.1.0 was not found appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
If you see this error in VS Code, you are missing the aspnetcore runtime (even though you may have installed the larger .net core runtime).

Basically, .net core is not the same as aspnetcore. They are different runtimes and thus, different downloads.

To get the approprirate aspnetcore.app 3.1.X version, try this microsoft download

If you still get the error, you may also need the corresponding .net core runtime

 

 

The post The framework microsoft.aspnetcore.app version 3.1.0 was not found appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/the-framework-microsoft-aspnetcore-app-version-3-1-0-was-not-found/feed/ 0
WebSockets–versus HTTP https://www.anujvarma.com/websockets-versus-http/ https://www.anujvarma.com/websockets-versus-http/#respond Fri, 17 Nov 2017 17:26:00 +0000 http://www.anujvarma.com/?p=5032 I am building a web app (or a mobile app). Can I eliminate HTTP altogether and use WebSockets? Not completely. To  perform a websocket handshake , one needs HTTP. Once […]

The post WebSockets–versus HTTP appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
I am building a web app (or a mobile app). Can I eliminate HTTP altogether and use WebSockets?

Not completely. To  perform a websocket handshake , one needs HTTP. Once the handshake is successful, you can switch to websockets entirely. If your app runs in a browser, you may also need to serve a HTML/JavaScript file(s) for the landing page, which will require HTTP.

What are the advantages and disadvantages of this solution?

Advantages

  • Full Duplex, stateful communication (unlike HTTP).
  • Real server push (you can easily notify clients) .
  • Add a layer on top of WebSockets (e.g. json rpc), and you can outperform HTTP.

Disadvantages

  • Bare bones TCP, so your  app may require another protocol on top of that. Which could affect performance and reliability. Especially if you want to mix textual content (e.g. json) with binary content (e.g. images). You may end up reinventing the HTTP protocol over websockets.
  • Not as many tools as for HTTP

What about Socket.io?

  1. Socket.io was designed to handle some shortcomings of websockets.
  2. Addresses Connection dropping issues with WebSockets.
  3. Old Browser Fallback capability.

The post WebSockets–versus HTTP appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/websockets-versus-http/feed/ 0
Using Asynchronous methods in .NET–Quick Notes https://www.anujvarma.com/using-asynchronous-methods-in-netquick-notes/ https://www.anujvarma.com/using-asynchronous-methods-in-netquick-notes/#respond Thu, 16 Jun 2016 20:10:38 +0000 http://www.anujvarma.com/?p=4246 I developed these notes just as a way to keep myself sane while writing Async methods in C#.  Quick Recap – Two types of threads for an ASP.NET programmer 1. […]

The post Using Asynchronous methods in .NET–Quick Notes appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
I developed these notes just as a way to keep myself sane while writing Async methods in C#. 

Quick Recap – Two types of threads for an ASP.NET programmer

1. Regular Windows Systems thread

2. .NET App Pool threads – Same thread pool that ASP.NET itself uses to process requests.   You would use a  ThreadPool.QueueUserWorkItem to use such a thread for your server side task – and yes, you would be taking away some of ASP.NET’s resources that it needs to do request processing.

How many concurrent ASP.NET requests per CPU?

UP from 12 requests per CPU (in .NET 3.5 and below),  there’s now 5,000 concurrent requests per CPU in ASP.NET 4 (and above).

Why use Async at all ?

Assume we have three operations – which take 100, 200 and 300 milliseconds respectively. With the synchronous call, total response time would be slightly more than 600 milliseconds. However, if the calls are made asynchronously, total response time would be slightly more than 300 milliseconds, because that is the duration of longest task/operation.

When to use Async ?

   Anytime that your server side ASP.NET code is making a database call, or a web service call or a network call or talking to the file system, that can be done asynchronously.

While that operation is in progress ASP.NET doesn’t have to be consuming a thread which is a CPU resource on that box while that operation is taking place.

And then once the operation is finished, ASP.NET will do the work to bring that request (rehydrate it), and then let it proceed with the result.

When NOT to use Async? – IIS versus Database Bottlenecks

The IIS thread pool can often handle many more simultaneous blocking requests than a database server. If the database is the bottleneck, asynchronous calls will not speed up the database response. Without a throttling mechanism, efficiently dispatching more work to an overwhelmed database server by using asynchronous calls merely shifts more of the burden to the database. If your DB is the bottleneck, asynchronous calls won’t be the magic bullet.

MultiThreading versus Async

Multithreading could encompass many more scenarios than Async. Typically Async is a request-response model where the response is delayed.

Multithreading could mean – do more than one task – without any consideration to the results (for e.g.  – a certain thread could be used for a fire and forget task).

What about Async and Await ?

Formalizes how non-blocking methods work in .NET.

The post Using Asynchronous methods in .NET–Quick Notes appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/using-asynchronous-methods-in-netquick-notes/feed/ 0
Kendo UI versus jQuery UI https://www.anujvarma.com/kendo-ui-versus-jquery-ui/ https://www.anujvarma.com/kendo-ui-versus-jquery-ui/#respond Thu, 04 Feb 2016 20:49:00 +0000 http://www.anujvarma.com/?p=3827 This is an (ongoing) compilation of some Kendo UI features (mainly GRID related) that have helped me save time (over doing it with jQuery UI) Offline Data Persistence InLine Grid […]

The post Kendo UI versus jQuery UI appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
This is an (ongoing) compilation of some Kendo UI features (mainly GRID related) that have helped me save time (over doing it with jQuery UI)

  1. Offline Data Persistence
  2. InLine Grid Editing

Offline Persistence

Your kendo grid still displays data in case of a missing network connection to the datasource (using the offlineStorage option to enable offline storage). The DataSource uses this value as a key when saving and loading its state. By default, the Kendo UI DataSource uses the localStorage option to persist its offline state.

OfflineStorage

 

In Line Editing

A common scenario is to toggle a grid cell into edit mode by simply clicking on the Edit row button – and update the data inside the cell. This is trivial to accomplish in the kendo grid by simply adding the .Editable property to the grid

<%: Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
        .Name("grid")
        .Columns(columns =>
        {
            columns.Bound(p => p.ProductName);
            columns.Bound(p => p.UnitPrice).Width(120);
            columns.Bound(p => p.UnitsInStock).Width(120);
            columns.Bound(p => p.Discontinued).Width(120);
            columns.Command(command => { command.Edit(); command.Destroy(); }).Width(250);
        }).Editable(editable => editable.Mode(GridEditMode.InLine))

Excel style filtering

The post Kendo UI versus jQuery UI appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/kendo-ui-versus-jquery-ui/feed/ 0
Enable IIS logging https://www.anujvarma.com/enable-iis-logging/ https://www.anujvarma.com/enable-iis-logging/#respond Mon, 19 Oct 2015 16:01:15 +0000 http://www.anujvarma.com/?p=3605 To Enable Logging Fire up Programs and Features then click on Turn Windows features on or off on the left side then select Internet Information Services\World Wide Web Services\Health and Diagnostics\HTTP Logging Location of Log […]

The post Enable IIS logging appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
To Enable Logging

Fire up Programs and Features then click on Turn Windows features on or off on the left side then select Internet Information Services\World Wide Web Services\Health and Diagnostics\HTTP Logging

Location of Log files

%SystemDrive%\inetpub\logs\LogFiles

OR

C:\Windows\system32\LogFiles\W3SVC1

 

 

The post Enable IIS logging appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/enable-iis-logging/feed/ 0
Rendering PDF in a modal popup – asp.net mvc https://www.anujvarma.com/rendering-pdf-in-a-modal-popup-asp-net-mvc/ https://www.anujvarma.com/rendering-pdf-in-a-modal-popup-asp-net-mvc/#comments Tue, 13 Oct 2015 20:24:26 +0000 http://www.anujvarma.com/?p=3591 Recently, I had to display a PDF (a pdf report, sent to my app as a byte stream) in a popup window. In asp.net MVC, using bootstrap, I was able […]

The post Rendering PDF in a modal popup – asp.net mvc appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Recently, I had to display a PDF (a pdf report, sent to my app as a byte stream) in a popup window. In asp.net MVC, using bootstrap, I was able to create a modal popup to CONTAIN the pdf. The problem was – how do I initiate the PDF streaming to the popup window (in other words, what ACTION will start sending the bytestream from the parent view to the popup view)?

Enter the OBJECT tag – a life saver. Basically, the object tag can host any binary object (in this case, a pdf file). All I had to do was call a URL action (GeneratePDF) from within this tag as shown below.

            <object id=‘pdfbox’ style=“width: 500px; height: 600px; overflow: hidden” type=“application/pdf” data=“@Url.Action(“GeneratePDF“, “Results“, new { id= @ViewBag.ID })”></object>

The controller needs to return a FILE object (created from the PDF byte stream). The object tag is smart enough to figure out that this is a PDF file (if you have pdf reader on your box) – and render it as such. Here are the different snippets of code to make this work.

 

Controller (PDF Generator)

  public ActionResult GeneratePDF(string id)
        {
           // This is just how I retrieved the pdf from a web service api. This could be a filesystem read for your use case 
            var api = new ResultsApi(http://……api/);
            dynamic apiResultPdf = null;
            try
            {
                apiResultPdf = api.QueryResultsPostDynamic(ConstructPdfLookupQuery(id));
            }
            catch (Exception e)
            {
                @ViewBag.Message = "The result service timed out!";
                return View("Error");
            }
            var deserializedResult = JsonConvert.DeserializeObject(apiResultPdf.ToString());


          // return a File action to the object tag
            return File(deserializedResult.pdf, "application/pdf");
        }

Index.cshtml

<input type='button' data-toggle=\'modal\' url='GetPdfResult?id=#=ID#' class='btn btn-primary' value='Pdf' data-modal-id='popupwindow' />




<script>  $(document).on('click', '#resultsgrid .btn-primary', function (e) {
      var foo;
      var origFocus = document.activeElement;
      e.preventDefault();
      var btn = $(this);

      btn.text('Fetching...');

      var url = $(this).attr('url');

      if (url.indexOf('#') == 0) {
          $(url).modal('open');
      } else {
          $.get(url, function (data) {
               foo = $('<div class="modal fade" id="modalfade" aria-hidden="true" tabindex="-1" role="dialog">' + data + '</div>').modal();
          }).success(function () { $('input:text:visible:first').focus(); });
      }

  });
  </script>



Popup.cshtml 

<style>
    /*.row {
        line-height:24pt;
        border: solid 1px black;
    }*/


    .modal-body {
        width: 600px;
        margin: 0 auto;
    }

    #pdfbox {
        width: 700px;
        height: 700px;
        border: 5px solid #ccc;
    }
</style>

<div class="modal-dialog" id="application-attribute-modal-edit">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true";</button>
 
            <h4 class="modal-title">Report ID = @ViewBag.ID</h4>
        </div>

        <div class="modal-body row">
            <object id='pdfbox' style="width: 500px; height: 600px; overflow: hidden" type="application/pdf" data="@Url.Action("GeneratePDF", "Results", new { id= @ViewBag.ID })"></object>
        
        </div>
    </div>
</div>

The post Rendering PDF in a modal popup – asp.net mvc appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/rendering-pdf-in-a-modal-popup-asp-net-mvc/feed/ 1
Enable javascript debugger – works for chrome and IE https://www.anujvarma.com/enable-javascript-debugger-works-for-chrome-and-ie/ https://www.anujvarma.com/enable-javascript-debugger-works-for-chrome-and-ie/#respond Wed, 12 Aug 2015 20:16:29 +0000 http://www.anujvarma.com/?p=3518 function onClick(detailUrl){debugger;}

The post Enable javascript debugger – works for chrome and IE appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
function onClick(detailUrl){debugger;}

The post Enable javascript debugger – works for chrome and IE appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/enable-javascript-debugger-works-for-chrome-and-ie/feed/ 0
Some telerik kendo mvc script issues https://www.anujvarma.com/some-telerik-kendo-mvc-script-issues-2/ https://www.anujvarma.com/some-telerik-kendo-mvc-script-issues-2/#respond Thu, 23 Jul 2015 18:20:23 +0000 http://www.anujvarma.com/?p=3446 I love telerik – I hate working out the correct inclusion order of javascript references. Here are some common issues I encountered with Telerik MVC (Kendo) UI . Controls not […]

The post Some telerik kendo mvc script issues appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
I love telerik – I hate working out the correct inclusion order of javascript references. Here are some common issues I encountered with Telerik MVC (Kendo) UI .

Controls not showing up

(e.g. Html.Kendo().DropDownList() appears as a text box instead of a dropdown). To figure out the underlying issue, CTRL-SHFT-J on your browser to see the javascript errors. Chances are it will be something along the lines of ‘ kendogrid is not a function ‘ or ‘ kendo something is not a function’

To fix this, check the script library includes. They need to be in the following order:

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/jquery.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/kendo.all.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/kendo.aspnetmvc.min.js")"></script>

JQuery Conflicts

If you are using jquery bundles, they need to appear AFTER the kendo jquery references. E.g.

<!DOCTYPE html>

<html>

<head>

    <meta charset="utf-8" />

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/jquery.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/kendo.all.min.js")"></script>

<script src="@Url.Content("~/Scripts/kendo/2015.1.429/kendo.aspnetmvc.min.js")"></script>

@Scripts.Render("~/bundles/jquery")

<body>

<div class="box-body">

<div class="col-lg-12">

<div class="form-group" id="experience-grid">

@(Html.Kendo().Grid(Model).Name("grid").Columns(columns =>....

</body>

</html>

Summary

These are some commonly encountered issues with Telerik’s Kendo UI for MVC. Powerful stuff, but can kill your afternoon if you are not aware of what goes where.

The post Some telerik kendo mvc script issues appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/some-telerik-kendo-mvc-script-issues-2/feed/ 0
MetadataException: Unable to load the specified metadata resource https://www.anujvarma.com/metadataexception-unable-to-load-the-specified-metadata-resource/ https://www.anujvarma.com/metadataexception-unable-to-load-the-specified-metadata-resource/#respond Fri, 25 Jul 2014 22:01:48 +0000 http://www.anujvarma.com/?p=2644 When you move your data layer to another project or another folder  – you may encounter the following exception MetadataException: Unable to load the specified metadata resource The Solution: The […]

The post MetadataException: Unable to load the specified metadata resource appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
When you move your data layer to another project or another folder  – you may encounter the following exception

MetadataException: Unable to load the specified metadata resource

The Solution:

The following res: (resource) references need to point to your newly placed model

<add name=”Entities” connectionString=”metadata=

    res://*/Models.MyModelName.csdl|

    res://*/Models.MyModelName.ssdl|

    res://*/Models.MyModelName.msl;

 

You do not need to fully qualify the namespace –the relative folder path (Models…) is all that is needed.

The post MetadataException: Unable to load the specified metadata resource appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/metadataexception-unable-to-load-the-specified-metadata-resource/feed/ 0
MVC apps–set as start page https://www.anujvarma.com/mvc-appsset-as-start-page/ https://www.anujvarma.com/mvc-appsset-as-start-page/#respond Wed, 23 Jul 2014 23:04:54 +0000 http://www.anujvarma.com/?p=2642 Of course, MVC does not have the concept of a web page – it is more a web view. The view cannot be accessed directly (unlike a page) – and […]

The post MVC apps–set as start page appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
Of course, MVC does not have the concept of a web page – it is more a web view. The view cannot be accessed directly (unlike a page) – and can only be accessed through a controller action. So , in Visual Studio,setting a razr view as the default start page is meaningless. In fact, VS will throw the following error (when you run the app)

Server Error in ‘/’ Application. /Views/Index.cshtml cannot be found

Solution

Project Properties –> Web –> Specific Page – CLEAR the URL !

 

That fixes it.

The post MVC apps–set as start page appeared first on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.

]]>
https://www.anujvarma.com/mvc-appsset-as-start-page/feed/ 0