Thursday, June 2, 2016

ERROR : The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[class]', but this dictionary requires a model item of type 'class'.

SOLUTION :

    public CLASSNAME gEtsinglerecord(int Id)
        {
            CLASSNAME retval = null;
            retval = Entity.CLASSNAME.Where(s => s.Id == Id).FirstOrDefault();
            return retval;
        }


We have to use "First or Default( )" to the get record based on SINGLE ID value. 

Tuesday, May 31, 2016

Error occurred during a cryptographic operation. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.

Server Error in '/' Application.

Error occurred during a cryptographic operation.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Security.Cryptography.CryptographicException: Error occurred during a cryptographic operation.

Source Error:


Line 53:                     //var prin = new GenericPrincipal(id, userRoles);
Line 54:                     //HttpContext.Current.User = prin;
Line 55:                     var ticket = FormsAuthentication.Decrypt(encTicket);
Line 56:                     var id = new UserIdentity(ticket);
Line 57:                     string[] userRoles = { "A" };


Source File: c:\Naresh\                                        Global.asax.cs    Line: 55

Stack Trace:


[CryptographicException: Error occurred during a cryptographic operation.]
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Homogen
izeErrors(Func`2 func, Byte[] input) +115
   System.Web.Security.Cryptography.HomogenizingCryptoServiceWrapper.Unprot
ect(Byte[] protectedData) +70
   System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
 +9692626
   CanPayApp.MvcApplication.MvcApplication_PostAuthenticateRequest(Object
 sender, EventArgs e) in c:\Naresh\05 31 2016\CanPayApp\CanPayApp\Global
.asax.cs:55
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecut
ionStep.Execute() +141
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&
 completedSynchronously) +69



Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

=============================================================================
=Cleanup code and open... 

For anyone who hasn't solved their problem, I was missing the "machineKey" entry for encrypt/decrypt in my web.config

=
Try clearing your cache and cookies in order to mitigate the error. I suspect some sort of error occurred when information was sent to or from the server.

Friday, May 13, 2016

The localhost page isn’t working in visual studio

Resolved::: solution> project properties> change iis express port number ----

Wednesday, March 9, 2016

Convert Datatable to List

private static List<T> ConvertDataTable<T>(DataTable dt)  
{  
    List<T> data = new List<T>();  
    foreach (DataRow row in dt.Rows)  
    {  
        T item = GetItem<T>(row);  
        data.Add(item);  
    }  
    return data;  
}  
private static T GetItem<T>(DataRow dr)  
{  
    Type temp = typeof(T);  
    T obj = Activator.CreateInstance<T>();  
  
    foreach (DataColumn column in dr.Table.Columns)  
    {  
        foreach (PropertyInfo pro in temp.GetProperties())  
        {  
            if (pro.Name == column.ColumnName)  
                pro.SetValue(obj, dr[column.ColumnName], null);  
            else  
                continue;  
        }  
    }  
    return obj;  

Tuesday, March 8, 2016

Visual Studio Expand/Collapse keyboard shortcuts


Collapse to Definitions: CTRL + M + O

Expand all Outlining: CTRL + M + X

Thursday, March 3, 2016

Not Running in Release Mode in Visual Studio

  • Right click Project
  • Properties
  • Build
  • Advanced
  • Set Debug Info to full or pdb only

Tuesday, March 1, 2016

Difference Between "string" and "String"

what is the difference between both (String and string)? After completing the execution of this program when we mouse over on string is shows class System.String and  when we mouse over on String it also shows Class System.String. Class System.String statement clarifying that string is the alias name of String.

Finally:
String is the alias name of String because both contain the same things 

Difference Between "string" and "String"

what is the difference between both (String and string)? After completing the execution of this program when we mouse over on string is shows class System.String and  when we mouse over on String it also shows Class System.String. Class System.String statement clarifying that string is the alias name of String.

Finally:
String is the alias name of String because both contain the same things 

Wednesday, February 24, 2016

Convert Number To Word

public string ConvertNumbertoWords(int number)
       {
           if (number == 0)
               return "ZERO";
           if (number < 0)
               return "minus " + ConvertNumbertoWords(Math.Abs(number));
           string words = "";
           if ((number/1000000) > 0)
           {
               words += ConvertNumbertoWords(number/1000000) + " MILLION ";
               number %= 1000000;
           }
           if ((number/1000) > 0)
           {
               words += ConvertNumbertoWords(number/1000) + " THOUSAND ";
               number %= 1000;
           }
           if ((number/100) > 0)
           {
               words += ConvertNumbertoWords(number/100) + " HUNDRED ";
               number %= 100;
           }
           if (number > 0)
           {
               if (words != "")
                   words += "AND ";
               var unitsMap = new[]
               {
                   "ZERO", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE", "TEN", "ELEVEN",
                   "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"
               };
               var tensMap = new[]
               {"ZERO", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"};

               if (number < 20)
                   words += unitsMap[number];
               else
               {
                   words += tensMap[number/10];
                   if ((number%10) > 0)
                       words += " " + unitsMap[number%10];
               }
           }
           return words;

       }

Monday, February 22, 2016

Difference between TextBox and TextBoxFor:

@Html.TextBox() is loosely typed method whereas @Html.TextBoxFor() is a strongly typed (generic) extension method.
TextBox() requires property name as string parameter where as TextBoxFor() requires lambda expression as a parameter.
TextBox doesn't give you compile time error if you have specified wrong property name. It will throw run time exception.
TextBoxFor is generic method so it will give you compile time error if you have specified wrong property name or property name changes. (Provided view is not compile at run time. )