Wednesday, September 2, 2020

SOLVED - IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies"

 In this tutorial we'll learn how to solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies"  

This error ocurrs while deploying an Asp.Net Core app to IIS .

First of all, search for the ERROR CODE on the Troubleshoot ASP.NET Core  :



Step by step how to  solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies" 

You'll find there that the .NET Core runtime in-process fails to start. OK.

So may be the Microsoft.NETCore.App or Microsoft.AspNetCore.App runtime isn't installed?

Check the "Modules" tab on your app on IIS . 

However, the Modules are there :



The cause stated at the troubleshoot, is that the version does not exists on the machine:




So, search for the download link on the following url :  Publish an ASP.NET Core app to IIS



Below the title "Install the .NET Core Hosting Bundle" , you'll find the download link :  

Current .NET Core Hosting Bundle installer (direct download)



Download it, and copy it to the machine where the IIS is installed:

Run it as Administrator, and RESTART IIS after the setup is finished (my website >>> STOP >>> START (or RECICLE)) :


That's all.... 
In this tutorial we've seen how to  solve the IIS Asp.Net Core Error "500.31 ANCM Failed to Find Native Dependencies. 
Happy programming.....
      By Carmel Shvartzman

כתב: כרמל שוורצמן










Saturday, August 1, 2020

How to install SAP Crystal Reports for using in Asp.Net

In this tutorial we'll learn How to install SAP Crystal Reports for using in Asp.Net  
However straightforward , the installation can be a bit trickier since the wizard won't let you install until you close ALL Microsoft applications, and it will give you a PROCESS ID of the software to close, which you will have to find for yourself , showing the following dialog :







Step by step  How to install SAP Crystal Reports for   using in Asp.Net



First, go to the    Download SAP Crystal Reports, developer version for Microsoft Visual Studio web page , and download the version that you need.
Then, start the setup as follows:













Now, as stated before,  the wizard won't let you install until you close ALL Microsoft applications, and at first it will give you the names of the software to close:



 You will need to open the Task Manager (ctl-alt-del) and close them manually :








But that is not all.  After that, the wizard won't let you continue the setup until you close ALL Microsoft applications, and it will give you a PROCESS ID of the software to close, which you will have to find for yourself , showing the following dialog:


Therefore, at the Task Manager, you will have to change the settings in order to display the PID Process Identifier of all programs running :



Only after that, you could find the PID of the processes to close :


That's all.... 
In this tutorial we've seen How to install SAP Crystal Reports for using in Asp.Net. 
In the next tutorial     Step by Step How to Add a SAP Crystal Report to an Asp.Net project     we'll see how to add the SAP Crystal Reports for using in Asp.Net.
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן











Saturday, July 11, 2020

Querying Entities' Properties in Web API OData RESTful with ODataController

In this article we enable the Querying of an Entity's Property in an Web API OData RESTful service with ODataController.
Our task here is to perform OData protocol queries in order to get the value of some Entity's property, the following query for example :
http://localhost:6954/Odata/Notes(10)/Body/$value


When developing an ODataController to create an OData Web API, having configurated the application properly, as in the previous tutorial, you get automatically support for the most common OData protocol's queries. You can then query the OData Web API using $metadata, $value, $select, $top, $skip, $filter and even $expand , to get the JSON response:
http://localhost:6954/OData/$metadata#Notes :

              /Odata/Notes?$filter=From eq 'Fry'





http://localhost:6954/OData/Notes?$skip=2&$top=10

http://localhost:6954/OData/Notes?$select=Body

There are some conventions to follow when developing an ODataController:

1) the controller's name must be the entity name, the root of the resource path:

      /Notes(10)      implies that the Web API will look for a controller named NotesController (case sensitive)

2) the Action name for fetching an Entity's property will be set according to the Entity type and the Property name, as follows:

  /Notes(10)/Body       
      means that the Web API will look for an Action method named GetBodyFromNote()

All this conventions can be found in the Microsoft Asp.Net official site.
Let's say we have an Entity named "Note" with some property called "Body" : we want to call the OData HTTP service with this URI:
      http://localhost:6954/Odata/Notes(10)/Body/

So, according to the OData protocol specification, we need an Action method named GetBodyFromNote(), marked with the attribute "[EnableQuery]" , which returns the required property from the Entity:


(COPY-PASTE THIS CODE) : 


 [EnableQuery(AllowedQueryOptions = AllowedQueryOptions.All)]
        public string GetBodyFromNote([FromODataUri]int key)
        {
            IEnumerable<Note> data = Repository.GetAll();
            var note = data.Where(n => n.ID == key) .SingleOrDefault();
            return note.Body ;
        }



Build & run the application, and type the URI to fetch the required property in JSON format:

http://localhost:6954/Odata/Notes(10)/Body/
Also, we can request ONLY the $value of the property:

http://localhost:6954/Odata/Notes(10)/Body/$value
That's all
In this post we've seen how we perform Querying Entities' Properties in Web API OData RESTful with ODataController. 

Enjoy programming.....
    By Carmel Shvartzman
כתב: כרמל שוורצמן

Wednesday, May 20, 2020

Step by step how to add custom headers using Asp.Net Core 3.0

In this tutorial we'll learn   how to add custom headers using Asp.Net Core 3.0 
We'll use Postman for testing purposes of a RESTful WEBAPI Core application, sending  HTTP POST requests. We'll start with a WebApi Core 3.0 application,  and we'll add an Extension Method to the Response class in order to append our headers.
See the code here:
https://github.com/CarmelSchvartzman/DOTNET/blob/master/HEADERS/ADD_HEADERS_EXTENSIONMETHOD





Step by step how to add custom headers using Asp.Net Core 3.0



First, we create a new Extension Method to the Response class in order to append our headers., in Visual Studio, as follows:





  public static class Extensions
    {
        public static void AddApplicationError(this HttpResponse response, string msg)
        {
            response.Headers.Add("Carmel-Error", msg);
            response.Headers.Add("Access-Control-Expose-Headers", "Carmel-Error");
            response.Headers.Add("Access-Control-Allow-Origin", "*");
        }

    }

On the startup.cs file , we add to  the Configure method , the following code:

  if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(b => {
                    b.Run(async ctx => {
                        ctx.Response.StatusCode = (int) 
HttpStatusCode.InternalServerError;
                        var err = ctx.Features.Get<IExceptionHandlerFeature>();
                        if (err != null)
                        {
                            ctx.Response.AddApplicationError(err.Error.Message);
                            await  ctx.Response.WriteAsync(err.Error.Message);
                        }
                         
                    });
                });
            }

This code catchs all exceptions globally, and also adds our headers to the response.
Send a request using Postman, and open the "headers" window to see them:












That's all.... 
In this tutorial we've seen  how to add custom headers using Asp.Net Core 3.0  
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן











Saturday, March 21, 2020

How to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget

In this tutorial we'll learn how to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget 
This JQueryUI Autocomplete will be showing as follows :



Step by step How to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget



First, we create a new ASPNET HTTP HANDLER, in Visual Studio, as follows:

using System.Web.Script.Serialization;
namespace WEBAPI_AJAX

    public class EmployeeHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string t = context.Request.QueryString["term"];

            Func<string, bool> pred = (w) => { if (w.StartsWith(t)) return true; else return false; };

            List<string> l = new List<string>()  { "albert","andrew","asterix","ddddd","eeeeee","fffffff","gggggggg","hhhhhh","iiiiii"};

            l = l.Where(pred).ToList();
            //context.Response.ContentType = "text/plain";
            context.Response.Write(new JavaScriptSerializer().Serialize(l));
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}





Then, we create the HTML file :

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery UI Autocomplete - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <link rel="stylesheet" href="/resources/demos/style.css">
    <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    <link href="../Content/bootstrap.min.css" rel="stylesheet" />
    <script>
        $(()=>{
       
            $("#tags").autocomplete({
                source:  'http://localhost:58776/HANDLER1.ASHX'
            });
        });
    </script>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="jumbotron">
                <div class="form-group">
                    <label for="tags" class="control-label col-md-2">Tags: </label>
                    <div class="col-md-10">
                        <input class="form-control" id="tags">
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
</html>




That's all.... 
In this tutorial we've seen how to write an HTTP Handler to feed an AUTOCOMPLETE JQUERYUI widget. 
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן











Friday, January 24, 2020

How to show a Bootstrap Alert by clicking a button

In this tutorial we'll learn how to show a Bootstrap Alert by clicking a button 

https://github.com/CarmelSchvartzman/BOOTSTRAP/blob/master/ALERT/ALERT_BY_BUTTON






How to show a Bootstrap Alert by clicking a button 



We create a new HTML webpage, as follows:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

</head>
<body>

<div class="container">
<div class='jumbotron'>
<h3>Open an Alert by clicking this button</h3>
<button class='btn btn-info btn-sm'  data-target='#myalert' data-toggle='modal'>Alert</button> 


<div class='modal' id='myalert'
  <div class='modal-dialog'>
    <div class='alert alert-info alert-dismissible'  >      <<<<<<<<<<<   DO NOT SET "FADE" !
      <strong>This is an alert opened by a button</strong>
      <button class='close' data-dismiss='modal'><span class='glyphicon glyphicon-cloud'></span></button>

    </div>
  </div>
</div>

</div>
</div>
</body>
</html>

Pay attention to the code marked bold . Tha't the important part.

That's all.... 
In this tutorial we've seen how to show a Bootstrap Alert by clicking a button  
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן











Friday, January 10, 2020

Calling a JS Promise for display in a showable Bootstrap Alert


In this tutorial we'll learn how to call  a JS Promise for display in a showable Bootstrap Alert  






Step by step how to call  a JS Promise for display in a showable Bootstrap Alert



We create a new HTML webpage , using the CDN from JQUERY and Bootstrap (that is only for displaying an Alert), as follows:


<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>

<script>
$(()=>{

///// the JS Promise :
const fnPromise = (msg)=>{

return new Promise((resolve,reject)=>{

     if(msg !== null && msg.length > 0) resolve('<strong> Success : </strong> ' + msg);
     else reject('Bad request');
    });
}

$('button').on({'click':()=>{
    
        fnPromise('This alert box indicates a successful calling to a Promise method.').then((ret)=>{
     $('#spanMsg').html(ret);
     }, (error)=>{$('#spanMsg').html(error); });
    }});

});
</script>
</head>
<body>

<div class="container">
  <h2>Showing Alerts with a click</h2>
  <p>This is an showable Alert including the call to a JavaScript Promise</p>
  <button class='btn btn-info' data-target='#a1' data-toggle='modal'  >Open Alert</button>
  <div class='modal' id='a1'>
  <div class='modal-dialog'>
  <div  class="alert alert-warning alert-dismissible"  >
    <a href="#" class="close" data-dismiss="modal" aria-label="close"><span class='glyphicon glyphicon-check'></span></a>
    <span id='spanMsg'></span>
  </div>
</div>
</div>
</div>
</body>
</html>


That's all.... 
In this tutorial we've seen how to call  a JS Promise for display in a showable Bootstrap Alert
Happy programming.....
      By Carmel Shvartzman
כתב: כרמל שוורצמן