Tuesday, November 1, 2022

Generate Random Numbers in .NET6

 We can generate random number using the following code:

Console.WriteLine("Generate Randoms!");

var objRandom = new Random();

var myValue = objRandom.Next();

Console.WriteLine($"{myValue}");

In the above example, you obtain an int number as result.

You can use the methods NextBytes and NextDouble to obtain the results to obtain random bytes or random doubles values.


In .NET 6 you can use the class RandomNumberGenerator present in the namespace System.Security.Cryptography.


  Console.WriteLine("Generate Randoms in .NET 6!");

   var objRandom = RandomNumberGenerator.Create();

   var objBytes = new byte[sizeof(int)]; // 4 bytes

   objRandom.GetNonZeroBytes(objBytes);

    var myResult = BitConverter.ToInt32(objBytes, 0);

    Console.WriteLine($"{myResult}");

Friday, October 28, 2022

Copy to Clipboard using Javascript

 Copying the text to clipboard makes it easier to use the web page, so users will definitely like this functionality. You can achieve it using JavaScript.

Note: For this function to work in production environment, make sure your website has SSL Certificate

Sample:

  <asp:Button ID="btnCopyResult" Visible ="false"   OnClientClick="CopyToClipBoard();"   class="btn btn-primary btn-sm"   runat="server" Text="Copy Result" />  

 <script type="text/javascript">

  function CopyToClipBoard()

 {

var sData = "Copy ME!";

try 

{

      navigator.clipboard.writeText(sData);

     return true;

 }

 catch (err) 

{

    alert('Could not write to clipboard', err);

    return false;

}

}

Monday, October 24, 2022

Means of Persisting Form Data

 There are many ways of persisting form data after the form has been submitted. Some of the more popular ways include the following:

  • The values of form fields can be stored in the Session object. Data can be added to the Session object with a line like this (in ASP.NET):

    Session("Name") = "Mike Davis";
    

    Session information can be stored in various locations: inside the ASP.NET runtime process, inside a dedicated Microsoft Windows® service, or inside a Microsoft SQL Server™ database. However, using the Session object, in any of these locations, is costly in server memory. In addition, you have to read the values out of session and put them back into the form on each page load. This routine code bulks up your pages.

  • Another option to persisting data is to duplicate your form content in a hidden field that is posted back to the server. The HiddenField control is used to store a value that needs to be persisted across posts to the server. It is rendered as an <input type= "hidden"/> element. Normally view state, session state, and cookies are used to maintain the state of a Web Forms page.


Error: 1260 This Program is Blocked by Group Policy Plesk

 1026 This program is blocked by group policy. For more information, contact the system administrator.(GoDaddy server):

We can also eradicate the error “1026 This program block by group policy. For more information, contact the system administrator.” while hosting the asp.net mvc application published copy to the GoDaddy account. We can solve the issues by removing all of the contents inside the system.codedom tag in web.config file. 

Go to web.config file in the project folder then search for system.codedom tag and removed all the contents inside the system.codedom tag. 

Monday, September 26, 2022

Adding an image and text both in asp.net button

  <asp:Button ID="btnTestSample"   Width="35"    Height="25" runat="server" Text="lb"  CssClass="cssTestSample"   />

 <style type="text/css">

    .cssTestSample{

        border: 1px solid #563d7c;

        border-radius: 5px;

        padding:     0px 25px 0px 3px;

        background: url(../Images/MyTestImage.png) 

            left 18px top 5px  no-repeat ;

   }


Wednesday, September 14, 2022

HTML Formatting Elements

Here goes HTML list of formatting elements:

  • <b> - Bold text
  • <strong> - Important text
  • <i> - Italic text
  • <em> - Emphasized text
  • <mark> - Marked text
  • <small> - Smaller text
  • <del> - Deleted text
  • <ins> - Inserted text
  • <sub> - Subscript text
  • <sup> - Superscript text

Friday, September 9, 2022

No iOS signing iddentities match the specified provisioning profile "Name of profile"

 To solve this issue, try the following steps:

  1. Check if the apple certificate (distribution/development) is still valid at developers.apple.com.
  2. if certificate has expired then create a new certificate.
  3. download the certificate and double click so that its added to xcode. Verify that certificate is present in xCode.
  4. Now import this certificate to apple keychain. Go to Keychain, click Login, click Certificates on the top bar, then select the certificate, right click it and export as a p12 file, pay attention to remembering the password.
  5. Move the p12 file to your Windows machine, go to Tools -> Options->Xamarin ->Apple Account in VS, and click View Details, click Import Certificate, import the p12 file and input the password. Then check if the profile is in %LOCALAPPDATA%\Xamarin\iOS\Provisioning\Profiles

Generate Random Numbers in .NET6

 We can generate random number using the following code: Console.WriteLine("Generate Randoms!"); var objRandom = new Random(); var...