Thursday, June 26, 2014

Step by step how to deploy a web site to IIS creating a virtual directory, an application pool and a Web Application

        By Carmel Schvartzman


In this tutorial we'll learn how to deploy a web site to IIS. We'll create a virtual directory, a new application pool , and then we'll upgrade the virtual directory to a Web Application.
We'll first create a Virtual directory, because may be that will be enough for holding your web site. But after that, we'll upgrade it to a Web Application, because if your site is an ASP.NET web site, you'll need additional functionality that only an IIS Web Application can give.
We'll create a new Application Pool, because of stability problems (if there is only one pool and this pool have any problem, then all the applications are affected) , memory leaks(if there is an application with a memory leak, and you decide to regular recycling it, then all the applications running on this pool will get affected) , and security reasons (when you want to give some applications certain rights, like writing to the disk, and others no, then you give each pool different rights).

We'll want to deploy a new MVC asp.net web site to IIS:






The first step will be to create a new Virtual Directory in IIS, so CTL-R and type "INETMGR":


Then add a Virtual Directory, pointing to the physical place of your site:


You can now browse and see your web site in IIS:


We're not done. We want to create a new Application Pool for the new site:



Set the .NET framework according to your needs:






Finally, only in case you have an ASP.NET web site to deploy, you upgrade your virtual directory to a Web Application:


Select the Application Pool we created before:


The virtual directory is now a Web Application:


Browse to your web site:






In this tutorial we've learned how to deploy a web site to IIS, creating a virtual directory, a new application pool , and  a Web Application..

That's all!! 
Happy programming.....

כתב: כרמל שוורצמן





Wednesday, June 25, 2014

Step by step how to send an Ajax request to get a Json response

        By Carmel Schvartzman


In this tutorial we'll learn how to send an Ajax request to get a Json response in ASP.NET MVC 4. We'll use the $.ajax() method to render just a sample JSON object traveling round-trip from client side to server side , and back from server side to client side.

We'll want to render a JSON object , via an Ajax request, as follows:





The HTML markup will be just a text input, a <span> to get the response text, and a button to send the request :



At the javascript file, we MUST specify that the response we are expecting is in JSON format, using the parameter "dataType" :

And the Controller will return a JsonResult containing a simple string but in JSON format:



The response will be showed in the web page as follows :





Now we want to get a JSON OBJECT from the server. Let's include the message inside an anonymous object and serialize it as JSON using the Json() constructor : 


The jQuery code will expects JSON of course (by using the "dataType" parameter) but this time we need to consider that the returned "data" IS AN OBJECT : therefore we get the message using object notation to get the object's property :  data . MsgFromServer : 




This is the jQuery code to copy-paste :
 $("input[id!=hello]").dblclick(function () {
        var input =  "{'msg':'" +  $("[id*=message]").val() + "'}";
        $.ajax({
            url: "Blog/SayHello",
            data: input ,
            contentType: "application/json",
            dataType: "json",
            type: "POST",
            success: function (data) {
                $("[id|=result]").prepend($("<b></b>").html("<i>" + data.MsgFromServer + "</i>"));
            }
        })
    });
 

Also, here you have the markup :

<h2>Get JSON from Server Side via Ajax</h2>
<input type="text" id="message" />
<input type="button" id="btn-getdatafrom-server" value="Get data from server" />
<span id="result"></span>

Then we send the request as follows:


And the response this time is a JSON object (with the message as a property):




This is the rendered JSON object in the web page :







In this tutorial we've learned how to send an Ajax request to get a Json response in ASP.NET MVC 4.  
That's all!! 
Happy programming.....

כתב: כרמל שוורצמן

Monday, June 23, 2014

How to Deploy an ASP.NET MVC 4 Application to a FREE Web Host

        By Carmel Shvartzman
In this tutorial we'll learn Step By Step how to Deploy an ASP.NET MVC 4 Application on a FREE Web Hosting
We'll deploy the following Asp.Net MVC Application to the FREE HOSTING Somee.com host:

How to Deploy an ASP.NET MVC 4 Application to a FREE Web Host


How to Deploy an ASP.NET MVC 4 Application to a FREE Web Host


Browse to Somee.com :


Select the FREE Hosting Package :
Deploy an ASP.NET MVC 4 Application to a FREE Web Host

You register and set the LOGIN info :


Continue to get a Free Hosting Package :
Type the SUBDOMAIN of your Web Site :

And CREATE the site :

Now go to the File Manager, to UPLOAD your MVC site :

Open your file system where your MVC project is stored, and ZIP the entire MVC Web Site :

Then click "Upload & UnZip" :

After a while, you'll see the MVC files at the host :

Now we must set the DATABASE. Create a LOGIN :

Create a DATABASE :






Take a look at the Database's settings :


Now, we'll need to CUT & PASTE the entire web site to the UP folder :



Now, you can browse to your web site. Of course, it will be an error, because the database connection at the web.config file is still pointing at your machine's sql server :


So let's change the connection string :


Where's the new connection string? At the SQL database properties view :


COPY the connection string, and open the web.config file :


There, find the "Provider Connection String" key :


And PASTE the new connection BETWEEN the " &quot; " :

That's not all. We'll keep getting an error because the database is empty. So let's create the tables using the automatically created sql SCRIPTS from the SQL Server Manager  :


First, copy ONLY THE TABLES , and after that, copy the FOREIGN KEYS alter scripts :


Go to "New SQL Query" :


And PASTE the scripts , ONE BY ONE (the alternative is, of course, running a batch file):

After you created all the tables, run ONE BY ONE the KEYS scripts .
Finally, let's see how to update a single file at the site .
Just DOWNLOAD the file, clicking the download icon at the right, edit the file, and UPLOAD it again, taking care that the "Overwrite existing files" option is on:


And that's all. Enter some data, and browse to your site:




That's all!! 
In this tutorial we've learned how to Deploy an ASP.NET MVC 4 Application on a FREE Web Host.  

Happy programming.....


כתב: כרמל שוורצמן