एउटा त्यस्तो दिनको पर्खाईमा छु, जुन दिन मेरो नाम मात्रै पनि मेरो सम्पूर्ण परिचय बनोस् ।

Category: Uncategorized

Steps to start with Ajax in Asp.Net MVC

What is Ajax?
we all know, AJAX means Asynchronous JavaScript and XML. It is a client-side script that communicates to and from a server/database without the need for a postback or a complete page refresh. The Ajax speeds up response time.
In other words, Ajax is the method of exchanging data with a server, and updating parts of a web page, without reloading the entire page.
Some of the Benefits of Ajax are:
  • Callbacks
  • Making Asynchronous Calls
  • User-Friendly
  • Improve the speed, performance and usability of a web application
Implementation of Ajax can be done in two way in ASP.Net Application:
  • using Update Panel and,
  • using jQuery
 What Advances have Been Made to Ajax?
JavaScript is the client-side scripting language and XML is a mark-up language to define data. And we have, JSON(JavaScript Object Notation) is as another mark-up language to define data as well. JSON is much easier to use with JavaScript than XML. After the combination of JavaScript and Ajax, the XML Web Services are being replaced by JSON Web Services.
Another major advance to JavaScript and Ajax is the JavaScript object library called jQuery, which is the free, open-source software. It is a wrapper for JavaScript. jQuery is used to write the JavaScript to navigate and manipulate a page and make asynchronous Ajax callbacks.
Hence, Ajax callbacks have become standard programming practices by using jQuery and JSON Web Services for designing and developing web applications.

Demonstration: Implementation of Ajax using  jQuery:

Step 1: Create a new Project and choose ASP.NET MVC web application.
Step 2: Just Ignore the built-in Models and Controllers and make your own model.
Here I am creating a model called “Students” having properties studentID, studentName and studentAddress as shown below:
Add “using System.ComponentModel.DataAnnotations;” Attributes to Validate Model Data and then build the project once.
Step 3: Lets create another model by inheriting the DbContext. It is a class that manages all the database operations, like database connection, and manages various entities of the Entity Model.
We can also say DbContext is a wrapper of ObjectContext. So, DbContext is a lightweight version of the ObjectContext and is exposes only the common features that are really required in programming.
Here I am creating a model called “StudentContext” as shown below:
Add “using System.Data.Entity;” that provides access to the core functionality of the entity framework.
Step 4: Now create a controller to written the code for inserting data into database, displaying data into view.
Here I am creating “Student” controller. Inside the Controller, I am creating an object of StudentContext for inserting and retrieving data from database. Also add the necessary namespace required.
Step 5: Now creating the action methods for Inserting and retrieving the data to/from the database.
Here I am creating an [HttpPost] action method “createStudent” for inserting the JSON-Formatted data to database. I am Using [HttpPost] attribute to Save/Post the data as below:
Similarly, I am also creating JSON method “getStudent” to retrieve data from database and return raw JSON data to be consumed by JavaScript in view as shown below:
Step 6: Now add a view to display the data and data inserting field. Here, I am adding a view named as “Index.cshtml”. Then, write the HTML codes for making the data input field, submit button and also for displaying the data in same page. You can use bootstrap classes for designing. Here I am using bootstrap. My designing code is as below:

Please enter the details below:



we can simply use the bootstrap class and call jQuery functions in ASP.NET MVC because during the project creation it will by default added to project and also

linked to the template.
Step 7: Now I will write the script for inserting the data as well as retrieve and display it to the view. Just after the HTML code finished add the script shown below:
we are using Ajax to refresh “tblStudent” so it refreshes only the particular table, rather than refreshing entire page. After clicking the “submitButton” the data from the input fields are taken in variable and redirected to action “createStudent” of “StudentController” to insert into the database. And, I have written a function “LoadData” to display the data from database to view continuously after inserting data. Inside “LoadData” function I am calling “getStudent” method which returns result in JSON and the JSON-Formatted data are presented in html by the underlying statements.
Step 8: Now, configure the Database connectionStrings in “web.config” file of the particular project as shown below:
In above connectingString “StudentContext” is the name of class inherited from abstract Class “DbContext” in “StudentContext.cs” file. “RAVI-KANDEL” is the name of the Database Server and “Student” is the name of Database. Change “RAVI-KANDEL” with your Database Server name. Finally, run your application and navigate to Student controller. Also you can configure “RouteConfig.cs” and set the controller to “Student” for direct navigation to the Student controller when loading the application.
You can add the records and can see added data in the table after the form-control as shown below:

Also, you can open the database server and see the data stored in database over there.
Please feel free to comment/feedback.
Happy Coding! 
Continue Reading

Threat Detection in SQL Database

Threat Detection is an awesome feature, which helps to detect anomalous activities in the databases which indicates potential Security threats to the databases.
This feature “Threat Detection” is in preview and supported for Azure SQL Database.

This feature helps to provide new security layer enables the database Users to detect and respond to the potential threats by providing security alerts on anomalous actions. Users can easily suspicious events using Azure SQL Database Auditing to determine if they result from an attempt to access, exploit data in the database. That’s why Threat Detection makes it very simpler to address potential threats to database without the need to be a security expert or an Advanced security monitoring systems.

For Example:

SQL injection is one of the most common Web application security issues on the Internet, used to attack data-driven applications. Attackers take advantage of application vulnerabilities to inject malicious SQL statements into application entry fields, for modifying data in the database.
Therefore, the “Threat Detection” feature helps to detect certain anomalous database activities indicating potential SQL injection attempts.

Get started with SQL Database Threat Detection:

Step 1: Login to Azure portal, using the credential of your Subscription.

Step 2: Go to the configuration blade of the SQL Database that you want to monitor. In the Settings blade, select Auditing & Threat Detection.











Step 3: In the Auditing & Threat Detection configuration blade turn ON auditing, which will display the Threat detection settings. Also turn on Threat Detection(preview). Enter the email address in which you want to receive notifications and check the email service & co-administration box. Finally save it.













Step 4: Explore anomalous database activities upon detection of a suspicious event like SQL Injection etc. You will receive an email notification upon detection of anomalous database activities.
The email will provide information on the suspicious security event including the nature of the anomalous activities, database name, server name and the event time.
In addition, it will provide information on possible causes and recommended actions to investigate and mitigate the potential threat to the database.


Step 5: In the email, click on the Azure SQL Auditing Log link,
which will launch the Azure portal and show the relevant Auditing records around the time of the suspicious event.










Step 6: Click on the audit records to view more details on the suspicious database activities such as SQL statement, failure reason and client IP.














Also, You can click Open in Excel to open a pre-configured excel template to import and run deeper analysis of the audit log around the time of the suspicious event. in Recent Excel,  Power Query and the Fast Combine setting is required.

That’s all f0r today keep on rocking.

#SQL #SQLdatabase #Azure

Continue Reading

CRUD operation MVC 5 Web App with Azure SQL Database.

In the earlier tutorial, I talked about the creating SQL database in Azure and connecting it through SQL Server Management Studio.
Now This Tutorial is to perform CRUD operation on Azure SQL Database through MVC 5 Web App.
First of all create a table inside the database. I have a table “tbl_info” which holds:
  • Id primary key
  • Name nvarchar,
  • Address nvarchar.
Then I am using Database first approach here. So, I am creating the model from the database.
Create an ASP.NET MVC Web Application in Visual Studio as shown below:

Create a Data Model as,
Right-click the Models folder in the Solution Explorer and select Add -> New Item.
Select ADO.NET Entity Data Model and give name to a model then click Add.
Choose EF Designer for database as a model from Entity Data Model wizard, then click Next.
Click New Connection on next window.
  • Enter the database server name.
  • Choose SQL Server Authentication.
  • Enter the Username and password of the database server.
  • Enter the Database name That you created, in my case it is “data-to-azure-sql”.
Test your database connection and click OK. Now your Entity Data Model Wizard should look like this:

Provide the connection string name and click next. In the next step you need to choose the objects for your model. Make sure to choose the table that you created earlier, Provide the namespace and then click on next. Then Build the project once.
Now time to create the Controller as,
Right-click the Controllers folder and select Add -> Controller.
In the Add Scaffold dialog, choose MVC 5 Controller with views, using Entity Framework.
Choose the Model Class, Data Context Class and enter the Controller Name as well.
Click the Add.
Go to the App_Start Folder and inside “RouteConfig.cs” change the Controller name “Home” to the Controller name that you entered earlier, It will help redirect you directly towards the Particular Controller Operations.
Finally, Run it into the browser. Now you are able to Create, Read, Update, Delete the records.
Also look to the database field you have created to see the data is saved there or not,
If any problem occurred feel free to ask me. I will help you.
That’s all for today. Thanks!
Continue Reading

Creating SQL Database in Azure and connecting through SQL Server Management Studio.

We all know that without creating the database we cannot connect. So lets, create the SQL database first.
First of all, Login to Azure portal using the credential of your Subscription.

Now, to create SQL Database got to New > Databases > SQL Databases as shown in figure below:


Then, In the SQL Database blade, Provide the Informations as shown below:

Database Name: The name of database you want to create.
Subscription: Choose your available Subscription.
Resource Group: Either use existing resource group or create new one.
Select Source: Choose the database you want, Here I choose Blank Database.
Server: You can choose existing database server if available, else create new one, I am creating new. To create New server do similar as shown in the New Server Blade.

Pricing tier: Choose the size and price of database that is suitable for you.
Collation: Which one you want.

Then, Pin it to dashboard for easy access and click on create, It will take some time to deploy Database.


After database is successfully deployed, its wizard will open automatically as shown below:


Now, SQL Database has been successfully created in Azure.

Then to connect it through SQL Server Management Studio follow the steps:

We need to add client machine IP to the fire wall so, go to Tools as shown below:


Click on open in Visual Studio, go to configure your Firewall. Firewall Setting blade will appears. Click on Add Client IP and then Save, as shown below:



Open SQL Server Management Studio:
Server Type: Database Engine
Server Name: Enter the name that you created earlier in Azure.
Authentication: SQL Server Authentication
Login: Username that you set earlier while creating database in Azure.
Password: Password that you set earlier while creating database in Azure.

Then, Click on connect.


You will be redirected to another preview, which seems as shown below:



Continue Reading

CRUD operation using Scaffolded item in MVC 5 Model First Approach

Well Guys, It is very simple to do CRUD operation in MVC using Scaffolded item.
lets begin:
Step1 : Create an empty ASP.NET Web Application in Visual Studio as shown below:
Step 2: Then add an empty model as shown below:
Step 3: Then,add the Model and entity as shown below:
Step 4: Add the properties that you want in the model by right clicking on the properties field as shown below:

 Step 5: After completion of adding the required properties you must generate the database from model as shown below:
Step 6: A dialog box will appear where you have to choose the database name, You can use the already made database or you can create from there as well. I am making the new database “CollegeStudent”.
Step 7: Other box will appears do as shown below. That automatically setups the necessary Connection strings for the connection with the database.
Step 8: Dialog box  will automatically close and will be redirected to the visual studio to execute the connections for .edmx as below:
Step 9: Now add the controller inside the controller folder as shown below:
Step 9: Choose MVC 5 Controller with views, using Entity Frame Work as below:
Step 10: Choose the Model name that you made when making the entity, also choose the context name that you made earlier and enter the content name that you want. In my case, I have as shown below:
Step 11:  Go to RouteConfig inside App_Start and change the controller name to the one that you made earlier and enter the action method name that you want to call when the page loads. In my case, I have shown as below:
Step 12:  Finally, run it in the browser. then you will get the view as shown below now you can create, add, delete menu there and go through it for proper operation as you need.
Thank you for you time! Keep visiting my website for more other blogs.
Continue Reading

How to buy a Top Level Domain from Microsoft Azure?

When you create a web app, Azure assigns it to a sub-domain of azurewebsites.net. For example, if your web app is named exploreitnepal, the URL is exploreitnepal.azurewebsites.net. Azure also assigns a virtual IP address. For a production web app, you probably want users to see a custom domain name. And We can use Azure credits to buy Custom Domains and host it as well. This feature is not possible from the Dreamspark pass of Azure. This Blog explains how to buy and configure a custom domain with Web Apps.


  • For instructions on using Traffic Manager to load balance traffic to a web app, use the selector at the top of this article to select the Traffic Manager specific steps.
  • Custom domain names cannot be used with Free web app. You must configure your web app for Shared, Basic, or Standard mode, which may change how much you are billed for your subscription.

If you don’t have a domain name for your web app, you can easily buy one on Azure Portal. During the purchase process you can choose to have WWW and root domain’s DNS records be mapped to your web app automatically. You also can manage your domain right inside Azure Portal.

Steps to Buy Domain Names:

  • In your browser, open the Azure Portal.
  • In the Web Apps tab, click the name of your web app. In my case, I am using “exploreitnepal” as shown below:

Buy domain

  • Click on Setting there, a new blade will appears as shown below:


  • Scroll down the blade and then select Custom domains and SSL as shown below:


  • Then click on the Buy Domain in Custom domains and SSL” blade as shown below:


  • In the Buy Domains blade, use the text box to type the domain name you want to buy and hit Enter. The suggested available domains will be shown just below the text box. Select what domain you want to buy. You can also purchase multiple domains at once. Then, Click the Contact Information as shown below:



  • Fill the domain’s Contact Information form and Click on OK.


  • Now you can choose to,
  1. “Auto renew” your domain every year
  2.  Opt-in for “Privacy protection” which is included in the purchase price for FREE
  3.  “Assign default host names” for WWW and root domain to the current Web App.


  • Click the Select on Buy Domains blade, then you will see the purchase information on Purchase confirmation blade. If you accept the legal terms and click Buy, your order will be submitted and you can monitor the purchasing process on Notification.


  • Domain purchase can take few minutes to complete. After getting the similar view as shown below, be sure that your domain has been bought.


Stay tuned for my next blog, where I will be talking about the Domain Name Configuration.

Happy Using Azure  #Happy Coding!!!

Continue Reading