Friday, 1 November 2019

HTTP Error 500.22 - Internal Server Error (An ASP.NET setting has been detected that does not apply in Integrated managed pipeline mode.)

The issue is caused by the pipeline mode in your Application Pool setting that your website is set to.
There are two types of solutions exists,
i/ Change the Application mode to classic in IIS.
ii/ In Web.Config file add this code,
    <configuration>
      <system.webServer>
         <validation validateIntegratedModeConfiguration="false"/>
      </system.webServer>
   </configuration>
Read More

Thursday, 22 February 2018

How to Set the favicon in MVC.

In this article, We will discuss about How to Set the favicon in MVC.

First Of all, Create an MVC Project and goto Layout Page.

Goto <head></head> section and there we need to write the following code which is given below,

<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />

where "favicon.ico" is our favicon.


Not only in Layout Page but also we can set the favicon for invidual page and  there we need to add the above code and which will set favicon for that individual page.
Read More

Sunday, 11 February 2018

Difference between First() and FirstOrDefault() in C#.

In this article, We will discuss about What is the difference between First() and FirstOrDefault() in C#.

First()
---------
- First method Returns the First element of a sequence.
- Generates Error If it does not contain any element.

Example:
------------
public ActionResult Index()
        {
            SampleEntities obj = new SampleEntities();

            int Id = 2;

            var memList = (from x in obj.Memberships where x.ID == Id select x).First();

            return View();
        }

In the above Code, We use Index Action method and used First() and When Id=2 match with database then it will return the result otherwise it Will generate the Error and Which is Shown in below figure,

FirstOrDefault()
--------------------
- FirstOrDefault method Returns the First element of a sequence, or a default value if the Sequence contains no elements. 
- Returns null if it does not contain any element.

Example:-

-------------
public ActionResult Index()
        {
            SampleEntities obj = new SampleEntities();

            int Id = 2;

            var memList = (from x in obj.Memberships where x.ID == Id select x).FirstOrDefault();

            return View();
        }

In the above Code, We use Index Action method and used FirstOrDefault() and When Id=2 match with database then it will return the result otherwise it Will return null and Which is Shown in below figure,

Read More

Saturday, 10 February 2018

Difference between List and IEnumerable in C#.

In this article, We will discuss about What is the difference between List and IEnumerable in C#.

List
------
- List is a Class.
- List is not read-only.
- We can able to add,delete items into List.

Example:-
-----------

      public ActionResult Index()
        {
            SampleEntities obj = new SampleEntities();

            var memList=(from x in obj.Memberships select x).ToList();

            return View();
        }

In the above example, We conside Index action method where memList is a List  and Whose add,delete method exists and Which is Shown in below figure,


IEnumerable
----------------
- IEnumerable is an Interface.
- IEnumerable is read-only.
- We can not able to add, delete items into IEnumerable because it is read-only.

Example:-
------------

public ActionResult Index()
        {
            SampleEntities obj = new SampleEntities();

            IEnumerable<Employee> objMem = _iemployeerepository.getListOfEmployee();

            return View();
        }

In the above example, We conside Index action method where memList is an IEnumerable  and Whose add,delete method does not exists and Which is Shown in below figure,


Note:- Depend upon the Situation we need to Use List and IEnumerable.
Read More

Database First Approach in MVC.

In this article, We will discuss about How to Create Database First Approach in MVC.

First of all, Create one Sample MVC Application and also Consider One Database and in that Database Create one table.

Goto Visual Studio -> Goto Solution Explorer.

Now, We need to add an "ADO.NET Entity Data Model" and Which can be add in any Folder or you can add under Project also and here, i added under my Models Folder.

Goto Models Folder -> Right Click on it -> Click Add -> Click "New Item" -> Then a new PopUp Will Come and there we need to select "ADO.NET Entity Data Model" and Which is Shown in below figure,


Click Add and a new Popup Will Come Which is Shown in below figure,


Click Next and a new Popup Will Come.

After that, Click New Connection and FillUp all the required Details and Click Ok.

Click "Yes, include the sensitive data in the connection string" and Which is Shown in below figure,


Click Next -> then We need to Choose the Entity Framework Version and Click Next.

In the last, We need to Choose What are the tables,Views and Stored Procedures and Functions need to add and Which is Shown in below figure,


Click Finish.

After that an edmx File added under that Particular Location and also a ConnectionString added under Web.config file, Which is shown in below figure,


By Using the Entities Class now we Can Perform our CRUD to that Particular table.

Note:- This is Just a sample Application and you can change as per your requirement.
Read More

Monday, 6 November 2017

Unable to update the EntitySet 'stConfigureEmployeeList' because it has a DefiningQuery and no element exists in the element to support the current operation.

This issue arises when you are not handling primary key in your table and try to do any operation in EntityFramework.
When there is no primary key exists in table then EntityFramework automatically take it as a View but in the Code we are considering it as a Entity so that at that time the issue will arise.

There are 2 solutions exists for this,

1/ Add Primary Key in your table and after that again add that table in edmx file and everything will work fine.
2/ if you don't want to add primary key then follow these steps,
   -> Right click on the edmx file, select Open with, XML editor
   -> Locate the entity in the edmx:StorageModels element
   -> Remove the <DefiningQuery> section entirely
   -> Rename the store:Schema="dbo" to Schema="dbo"
   -> Change store:Type="Views" to store:Type="Tables"
Read More

How to Enable debugging in Bundling?

Whenever we use any .js file then there we can easily able to debug and that time by default <compilation debug="true"> in web.config file.
But Bundling is a feature that makes it easy to combine or bundle multiple files into a single file and as <compilation debug="true"> is bydefault true so you can't be able to debug directly.

To Enable debugging in Bundling there are 2 steps exists:

1/To Enable debugging in Bundling we need to set the debug value to "false" in the web.config file like this,
  <system.web>
    <compilation debug="false"/>
  </system.web>

2/Otherwise we can add BundleTable.EnableOptimizations=true either in RegisterBundles Method of BundleConfig.cs or in   Application_Start() method of Global.asax.cs page.
Read More

How to check your web application target to Which Framework?

To Check that whether my application target to which framework then please goto Web.config file and after that find out
<system.web> 
</system.web> 
and within that
<compilation debug="true" targetFramework="4.5" /> should be present.
If targetFramework="4.5" means it is targeting 4.5 .net Framework.
Read More

How to overload action method in mvc?

Overloading means the same function name with different parameter or signature.

But, when we try to apply the same overloading in MVC then it will Show you the error like "Ambiguous" because the HTTP does not undestand Polymorphism.

To Resolve the error we need to Use "ActionName" attribute.

Example:-

public class TestController : Controller
{
public ActionResult LoadEmp()
{
return Content("Load all Employee.");
}

[ActionName(LoadEmpByName)]
public ActionResult LoadEmp(int Id)
{
return Content("Load Employee based on Id.")
}


}
Read More

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

This issue is Completely related to EntityFramework and this issue arises whenever you have installed EntityFramework in one project at that same time section is added in your web.config or app.config file like this,

Web.Config or app.config:-
------------------------
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
</configuration>

But later when you update the EntityFramework some times the Version will not Update in Web.Config  or app.config and while running and Using EntityFramework in Program it will Show you the Error like this "The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception".

To Resolve this Error,First Check what is the Current Version of EntityFramework in your References. Whatever the Version is Present in References Update the Same Version in Web.config or app.config.

Example:-
---------
Let's Say i had previously 5.0.0.0 and now i Updated to 6.0.0.0 So we need to Change the same thing in Web.config or app.config.
Web.Config or app.config:-
------------------------
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
</configuration>
Read More

Friday, 3 November 2017

Max Json length exceeded Error.

This issue arises when you have set some value in maxJsonLength and trying to use json value which is greater than that set value.

maxJsonLength is an int type so we can set it's maximum value equal to int type which is as 2147483647.

Example:-
----------------

<configuration>
  <system.web.extensions>
    <scripting>
        <webServices>
            <jsonSerialization maxJsonLength="2147483647">
            </jsonSerialization>
        </webServices>
    </scripting>
  </system.web.extensions>
Read More

Wednesday, 27 September 2017

Difference Between maxRequestLength and maxAllowedContentLength.

maxRequestLength:-
--------------------------------
1/The maxRequestLength indicates the maximum file upload size supported by website.
2/maxRequestLength datatype is int.
3/Maximum value supported by maxRequestLength is 2147483647.
4/
Example:-
----------
<system.web>
    <httpRuntime maxRequestLength="2147483647"/>
</system.web>
5/maxRequestLength is in KB.


maxAllowedContentLength:-
-------------------------------------------
1/The maxAllowedContentLength indicates the maximum length of content in a request supported by IIS.
2/maxAllowedContentLength datatype is int.
3/Maximum value supported by maxAllowedContentLength is 2147483647.
4/
Example:-
----------
<system.webServer> 
         <security>
                 <requestFiltering>
                           <requestLimits maxAllowedContentLength="2147483647" />
                 </requestFiltering>
         </security> 
</system.webServer>
5/maxAllowedContentLength is in Bytes.


So you need to set both in order to upload large files.
Read More

Max request length exceeded Error.

This issue arises when you have set some value in maxRequestLength and trying to upload a file which is greater than that set value.


maxRequestLength is an int type so we can set it's maximum value equal to int type which is as 2147483647.



Example:-

----------


<system.web>

    <httpRuntime maxRequestLength="2147483647" />
</system.web>
Read More

Friday, 22 September 2017

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

This issue is related to EntityFramework.

This issue arises when we have some required Field in some tables and we didn't provided any values to it or else we are passing null in it and calling saveChanges().

To resolve this error either we need to pass required Field values or we need to remove that required Field.

In the below image i showed one example of Same error and if i pass that required field then everything will work fine.



Read More