Friday, 12 January 2018

C# UWA StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'

Error: StatusCode: 415, ReasonPhrase: 'Unsupported Media Type'

Root cause:

        var jsonContent = JsonConvert.SerializeObject(InputContent);
       StringContent content = new StringContent(jsonContent );

       var result = await client.PostAsync("http://localhost/MyAPI/api/login", content);

content is not having right media type

Solution:

format content to right media type

  var jsonContent = JsonConvert.SerializeObject(InputContent);
       StringContent content = new StringContent(jsonContent ,Encoding.UTF8, "application/json"); 

       var result = await client.PostAsync("http://localhost/MyAPI/api/login", content);



Saturday, 23 December 2017

Error: To install this application you need either a Windows developer license or a sideloading-enabled system


Solution:
Open Your project in VS as Administrator mode
Click on Tools-->NuGet Package Manager-->Package Manager console
Run below command
Show-WindowsDeveloperLicenseRegistration
It will open Setting for Developers
Select Developer Mode
Click Yes in the prompt
Go back to VS Package Manager console
Run below command
Get-WindowsDeveloperLicense
It has to show IsValid True.
Now Reopen you XAML page, it should work

Thursday, 30 November 2017

IIS 10: HTTP Error 500.19 - Internal Server Error


Search for "Turn windows features on or off"
Check "Internet Information Services"
Check "World Wide Web Services"
Check "Application Development Features"
Enable all items under this

Monday, 20 November 2017

The remote server returned an error: (403) Forbidden



Go to run
type: services.msc
Search for below service and start
SQL Server Agent (MSSQLSERVER)
Now you should not get any error

Friday, 17 November 2017

C# shim not working in VS 2015

Go to Test Project.
Delete all files under "Fakes" folder
Remove all Fakes references from "References"

Under reference -->Right click add new reference, browse
Select:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\PublicAssemblies\Microsoft.QualityTools.Testing.Fakes.dll
This should be 12.0.0.0

Go to references right click on Dll Select "Add Fakes Assembly"

Now you will see new references with name .Fakes and under "Fakes" folder new files will be added

Now build and run test cases.


It should work fine

Monday, 13 November 2017

SQL injection

using (MySqlConnection objConn = new MySqlConnection(ConnString))
{
   
// string sql = "SELECT UserId FROM User WHERE " + "(email = '" + email + "' AND " + "password = '" + password + "')";//Never use this way, it will leads to SQL injections
    string sql = "SELECT UserID FROM User WHERE email = @email and password = @password "; //This way we r createing SQL statement dynamically
    using (MySqlCommand cmd = new MySqlCommand(sql))
    {
         cmd.Connection = objConn;
         cmd.Parameters.AddWithValue("@email", email);
         cmd.Parameters.AddWithValue("@password", password);  
  try
           {
             cmd.Connection.Open();
             var userId = cmd.ExecuteScalar();
         }
         catch (SqlException sx)
         {
             // Handle exceptions before moving on.
         }
     }
}