why console isn't working in this code RRS feed

  • Question

  • User887623398 posted


    I'm trying to make an online app to send images to Instagram for educational purposes.

    This is just a simple page but the console hasn't any activity.

    Please inform me if you can.

    Here is the code:

    @page "/"
    @using System;
    @using System.Collections.Generic;
    @using System.IO;
    @using System.Threading.Tasks;
    @using InstaSharper.API;
    @using InstaSharper.API.Builder;
    @using InstaSharper.Classes;
    @*@using InstaSharper.Examples.Samples;*@
    @using InstaSharper.Logger;
    @*@using Microsoft.AspNetCore.Components.Web;*@
    <input type="text" id="uName" @bind="username" @bind:event="oninput" />
    <input type="text" id="pword" @bind="password" @bind:event="oninput" />
        <b>username: </b> @username
        <b>password:</b> @password
        <button type="button" @onclick="@OnEnter">enter</button>
        public string username { get; set; } = string.Empty;
        public string password { get; set; } = string.Empty;
        public string Message { get; set; } = string.Empty;
        private static IInstaApi _instaApi;
        void OnEnter()
            Message = "ttt";
            var result =   Task.Run(MainAsync).GetAwaiter().GetResult();
            if (result)
        public static  async Task<bool> MainAsync()
                var userSession = new UserSessionData
                    UserName = "username",
                    Password = "password"
                var delay = RequestDelay.FromSeconds(2, 2);
                // create new InstaApi instance using Builder
                _instaApi = InstaApiBuilder.CreateBuilder()
                        .UseLogger(new DebugLogger(LogLevel.Exceptions)) // use logger for requests and debug messages
                //string Message = "ggg";
                return true;
            catch (Exception e)
                //string Message = e.Message;
            return false;



    Tuesday, June 23, 2020 2:16 PM

All replies

  • User-474980206 posted

    Console.Write() only works with server side Blazor, and it writes to the server console (which is not available if hosted with IIS). run directly with dotnet. to write to the browser console:

    await jsRuntime.InvokeAsync<string>("console.log", "hello world");

    Tuesday, June 23, 2020 8:32 PM
  • User887623398 posted

    Thanks, Bruce. Should I add javascript or any namespace?

    Is there any way to alert in Blazor. like:

    await JSRuntime.InvokeVoidAsync("alert", "Hello world");

    Wednesday, June 24, 2020 3:35 PM
  • User-474980206 posted

    simple article on javascript interop


    Wednesday, June 24, 2020 3:49 PM
  • User887623398 posted

    Just javascript should be used?

    There isn't any other way? for example in C#?

    Wednesday, June 24, 2020 8:16 PM
  • User-821857111 posted

    Console.Write() only works with server side Blazor,
    Works fine for me in a client app - writes to the browser console.

    Monday, June 29, 2020 8:09 AM