Showing posts with label MVC. Show all posts
Showing posts with label MVC. Show all posts

Wednesday, 20 July 2016

Installing Core

Steps To Install Core


Step 1. Before Installing Core Let Fulfill Its Prerequisites As Below -

First you need to Install Visual Studio 2015 . You Can Download Free Visual Studio Community Edition From Link below -
Download Visual Studio 2015

For Mac & Linux Users You Can Use Visual Studio Code -
Download Visual Studio Code & Read Its All Details 

Step 2. After Download & Installing Visual Studio 2015 you need to make sure you have Visual Studio 2015 Update 3 Installed . You Can Download Visual Studio 2015 Update 3 From Link Below -
Download Visual Studio 2015 Update 3

Real ALL Details About Visual Studio 2015 Update 3 Here -
What's New Added in Visual Studio Update 3

Step 3 -  Please Check Out All Dependencies of Core Before Installing it . See All Dependencies of Core For All OS -
Dependencies of Core

Step 4 - Now Download & Install Core From link below -
Download Core

Step 5 - Now Core is Setup Head Towards Next Post To Make First Sample App in Core To Make Ensure its setup Correctly . Link TO Next Post is Below - 

Friday, 3 June 2016

Difference Between MVC and webforms

The main advantages of The Official Microsoft ASP.NET Site MVC are:
  • Enables the full control over the rendered HTML.
  • Provides clean separation of concerns(SoC).
  • Enables Test Driven Development (TDD).
  • Easy integration with JavaScript frameworks.
  • Following the design of stateless nature of the web.
  • RESTful urls that enables SEO.
  • No ViewState and PostBack events
  • SEO friendly URL by design
  • No ViewState (this may seem a bit of moving backward to some), but overall a good design
  • Clean View Markup (no additional HTML emitted)
  • 100% extensible. You can add your own controller with IOC, switch view engines at will, control model binding at wish etc
  • Rich UI support (possible through client side JS libraries like jQuery UI and others)
  • Pluggable architecture
  • Out of the box minimal IOC support
  • Out of the box support for mitigating antiforgery attacks and XSS vulnerability
  • MVC is Faster by default because of lack of viewstate and clean markup. But performance is subject and MVC by design is more performant that traditional The Official Microsoft AspDotNet webforms
Limitation of MVC 
  • There is little Bit Long Learning Curve as compared to Asp.Net webforms 
The main advantage of Aspdotnet Web Form are:
  • It provides RAD development
  • Easy development model for developers those coming from winform development.

Difference Between MVC and webforms

Tuesday, 17 May 2016

Tempdata vs Session in MVC

Why Sessions are Not Recommended to use in MVC

One of the Fundamental Principal of Asp.Net MVC Framework is  Web is Stateless And AspDotNet MVC is Stateless AspDotnet WebForms is a try to make Stateful Modal But Its difficult to main it as this modal does not exist . Sessions Create lot of load on Cache that was biggest problem .

Using Session in AspDotNet MVC is like Putting APPLE Logo on Asus Laptop and Calling it Apple Laptop . Reality does not change .

What Is Alternative To Session in MVC

You can use TempData in place of Session . Tempdata is limited form of Session . Don’t Use Session in MVC as you are already having Tempdata and one benefit of Using Tempdata is They will automatically deleted no need to clear or remove them as we do with session

How To Use TempData In MVC

When Data is TempData is read it is immediately market for deletion at the end of request . That means you can use Value Tempdata In Tempdata Only at the Next Request . See Example Below - 

TempData is Filled With Data

TempData["SomeTemp"]= "Hey! This is MVC" ;

Tempdata Accessed in Second Request 

Object value = TempData["SomeTemp"] ;

Value in Tempdata will be Cleared After Above Line of Code . If you access in after that line of code after above line you will not found it there it will be deleted

Keep And Peek Methods 

Peek And keep methods are used to read value without marking it for deletion after reading its value . So it is acutally helping us to retain its after its first read instead of deleting tempdata

With Peek Method We get the value of Tempdata Without Marking it For Deletion . In this method we access the Tempdata value using Peek Method That tells it to Hold Value and does not mark it for deletion

With Keep Method we hold the Value of Tempdata that was marked for Deletion after its  first read . so it is using two different calls . First one is getting Tempdata Value then Second call is To Save Tempdata From Deletion

Tuesday, 28 April 2015

ASP.NET MVC Action Return View Not Changing URL

The return View(.......) in Action of Controller is the statement that we use to return the view View for a Particular Controller Request . But Return view will return the view exactly you want and render the view but it will not change or target the user to target url  . The simple solution is below -

Code For an Action -

public ActionResult Start(SomeViewModel someViewModel)
  return RedirectToAction("SomeOtherAction");


  return RedirectToAction("Action Name", "Controller Name");

So , In code above We are using RedirectToAction instead of using  return view this can be used in total of 6 variants .

I have give 2 of simple one . In Parameter to these actions you need to pass the controller and action name according to variant you choose

Wednesday, 11 February 2015

HTTP Error 500-22 - Internal Server Error The page cannot be displayed because an internal server error has occurred

Now At 11:47 PM I am going to write about how to solve HTTP 500.22 - Internal Server Error . This error is really very Bad Boy . It only display Error Message and does not give any detailed information about error as we don't normally allow for that . So Now I am going to give information how today Solved this error and what will be sure short and easy steps to solve this error so that you save your time .

I First tried to set CustomErrors="Off" in web.congig file just after <system.web> tag start But it does not helped so first i need to find way to see the error . So only way to see the error is through log file . I was using azure so I decided to turn on azure logging to check what is error

Enable Logging In Microsoft Azure Portal -

- Enable Application Diagnostics Logging 

1. Login to Azure Portal . In sidebar click on websites . Click on desired website
2. Now click on configure In Top Menu and scroll down and find 'Application Diagnostics'
3. Once found Do configuration as shown below -

Application Diagnostics For Application Logging - Windows Azure
Application Diagnostics For Application Logging - Windows Azure

- Enable Web Server Logging 

1. Login to Azure Portal . In sidebar click on websites . Click on desired website
2. Now click on configure In Top Menu and scroll down and find 'Web Server Logging'
3. Once found Do configurations as shown below -

Web Server Logging - Windows Azure
Web Server Logging - Windows Azure

4. After Doing Both Diagnostics Configuration . you must Save and Restart Azure Website .

How To Find Error In Azure Website Log

1. Now after Enabling Log you can see your log by logging in your FTP Client like CuteFTP or      FileZilla( In my case) . First login to your FTP Client of that website

2. Now at root you can see a folder named LogFiles as shown below -

LogFile In windows Azure
LogFile In windows Azure

3. Open the folder and then find a folder named 'DetailedErrors' Now open the folder here you can 4. see all your errors details for that particular website . as shown below -

Azure Website Log File Detailed Errors
Azure Website Log File Detailed Errors

5. So choose the latest file and download it to your computer and open it in browser and It will show you error in your azure website in Detail so that we can know error information to solve the error . In my case error was HTTP Error 500.22 error as shown by log file below snapshot -

Find Error Using Logs in windows Azure
Find Error Using Logs in windows Azure

 Cause of  HTTP Error 500-22 - Internal Server Error

The Main cause of  "HTTP Error 500-22 - Internal Server Error  The page cannot be displayed because an internal server error has occurred" is Managed Pipeline Mode in Application Pool . Integrated Pipeline Mode of Application Pool does not support some services and functionalities 

Solution For HTTP Error 500-22 - Internal Server Error  

Step 1- Change Application Pool From Integrated Pipeline Mode To Classic Pipeline Mode

FOR IIS USERS ON Windows Server

1. Open Control Panel Then GoTo Administrative Tools
2. Then choose IIS Manager
3. Now Change  App site's Managed Pipeline from Integrated to Classic.


1. Login to your Azure Portal . In sidebar click on websites . Click on desired website
2. Now click on configure In Top Menu and Under General Section find 'Managed Pipeline Mode'
3. Once Found Change mode from Integrated To Classic Pipeline Mode  as shown in snapshot below

Enable Classic Pipeline Mode Application Pool IIS and Windows Azure
Enable Classic Pipeline Mode Application Pool IIS and Windows Azure

Now after this change No other change will be required Everything is solved now . browse your website everything will be fine .

In case you face some Problem or Same Error Persist You may try the following solutions that can help in resolving issue 

 Changes in Web.Config File (Optional )

1. First open your Web.Config file and Search for <Configuration> Tag opening part and then insert following code in it and it should look like below --

        <validation validateIntegratedModeConfiguration="false"/>

Sunday, 25 January 2015

Using Entity Framework Code First Migration Asp MVC

 Code First Database Initializers

 Before understanding code first migrations, let's have a look at Code First Database Initializers   provided by Entity Framework. When you follow EF code first approach, then you have three op tions for initializing database as given below–
  1. CreateDatabaseIfNotExists

    This is the default database initializer class used by Code First. This class creates a database only if it doesn't exist. This initializer helps you to avoid any accidental deletion of the database.
  2. DropCreateDatabaseWhenModelChanges

    This database initializer class drop the existing database and re-creates it if there is a mismatch between the model classes and table schema. This initializer is useful during starting phase of development and testing when models are changing often and there is no concern about the existing database records.
  3. DropCreateDatabaseAlways

    This database initializer class always drop and creates a new database, whether it is already present or not with every run of the application. This initializer is useful during testing when you want to run the application with a fresh set of data.

    Why Code First Migrations?

    The above three database initializing approach become fail when you add new model classes and you want to update existing database without any deletion or change. To achieve this, you need to use EF code first migrations which allow you to update existing database with new model classes changes and your existing database remains same with your database records.

    Visual Studio Package Manager Console

    To create the database for these two entities within your application, go to the Package Manager Console option as shown below:

    Creating New Database

    Running Commands

    Run the following command to configure migrations within your project and for creating new database.
  4. Enable migrations

  5. Create migration

    Add-Migration MigrationsName
  6. Create upgrade/downgrade script


  7. Updating Existing Database

    Suppose you have added one more class named as Customer into your data model classes as given below:

    Running Commands

    Now for updating the database with new changes run the following commands as given below:
  8. Create migration

    Add-Migration MigrationsName
  9. Create upgrade/downgrade script