Wednesday, December 2, 2015

MVC: Display string as HTML from database to view

Following is the way to display html in view:

For aspx:
<%= System.Web.HttpUtility.HtmlDecode(@Model.Html) %>

For Razor:

@Html.Raw(Server.HtmlDecode(@Model.Html))

Update EDMX from database

In database first approach, you create your database first and then you generate model from database. This creates respective entities in your project.

However any change in database schema, does not reflects automatically in your model. For this you need to update your model. Following are 2 techniques:


  1. Delete and create(not prefered solution): Here you just need to delete entitiy in model browser. And then you just need to right click and click "Generate Model from Database" this regenerate model from database. This is a good solutions for hobby projects or test projects. However this is not recomended.
  2. Update entities from database: Below are the steps to update entities from database:
    1. Right click model(in edmx file).
    2. Click update model from database:
    3. There ate three tabs(Add, Refresh & Delete).
    4. In Refresh tab expend tables > dbo(schema) > and select updated entity.


All done. Now you

Tuesday, November 3, 2015

IIS - Worker Process, ISAPI Extension, Application Pool, Web Farm & Web Garden

Application Pool:
An application pool is a group of one or more web applications that are served by a worker process(w3wp.exe) or set of worker processes.
OR
An application pool is a group of one or more worker processes, configured with common settings that serve requests to one or more applications.

Means n number of web application can be served by n number of worker process using same application pool. Applications within an application pool shares the same worker process.

You can also create multiple application pools to isolate multiple web application. This way you will be able to apply different level of security on multiple apps. Also an error in one app will never affect other applications.

Worker Process(w3wp.exe):
Application pool passes every request to worker process. Worker process (w3wp.exe) checks the URL of the request to load the correct ISAPI extension. ISAPI extensions are the IIS way to handle requests for different resources(like images, javascript, css, aspx, ashx etc). When we install asp.net, its ISAPI extension (aspnet_isapi.dll) and adds its mapping in IIS.

ISAPI Extension:
ISAPI Extensions are true applications that run on IIS. They have access to all of the functionality provided by IIS. ISAPI extensions are implemented as DLLs that are loaded into a process that is controlled by IIS. Clients can access ISAPI extensions in the same way they access a static HTML page.

Web Farm:
A Web Farm is group of servers acting as a single server. It could be a setup of multiple servers work togather to host a single website(or any other application). A load balancer can be used to devide traffic between various servers.

Web Garden:
By default each and every application pool contain single worker process. But we can change associated worker process. An application pool with multiple worker process is called Web Garden. Following is the way to manage number of worker process in IIS:

1. Go to IIS(inetmgr).

2. Click on Application Pools.
3. Right click desired Application Pool.
4. Go to Advance Settings.

5. Increase Maximum Worker Processes.

Conver JSON to XML

Following is the method to convert json to xml:

string ConvertToJson(string json)
{
    XmlDocument rootxml = new XmlDocument();
    XmlDocument doc;
    doc = JsonConvert.DeserializeXmlNode(json,"root");
    return doc.OuterXml;

}

For this we need to use newtonsoft.json dll to our project.
This dll can be installed by package manager. Perform following steps to download this package:

1. Go to Tools > Library Package Manager > Manage NuGet Packages for Solution...

2. Search for newtonsoft
3. Install Json.net

Thursday, October 29, 2015

SQL Server: Save changes is not permitted. Resolution

Save changes is not permitted. The changes you have made require the following tables to be dropped and recreated. You have either made changes to a table that can't be re-created or enabled the option Prevent saving changes that require the table to be re-created.

User canceled out of save dialog.

Solution:

  • Go to Tools > Options

  • Go to Designers > Table and Database Designers
  • Uncheck the Prevent saving changes that require the table recreation.