I
I
Ivan2014-10-20 23:53:06
Java
Ivan, 2014-10-20 23:53:06

How to build on c# + asp.net an analogue of an application on java + jsp?

Good afternoon! I am interviewing in one office for an entry level developer. They work on the Microsoft stack, but knowledge of C # is not important for them for this vacancy, they take with knowledge of any language. Given a test task:
the simplest web page that shows data from the database. I would do it like this: jsp page, servlet that processes the request and JDBC for the select from the database. How to do it using c#?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Lebedev, 2014-10-21
@sputnic

Well, the easiest option, but not in the style of ASP.net WebForms or MVC. But this is very common in one of my projects.

<%@ WebHandler Language="C#" Class="Default" Debug="false" %>

using System;
using System.Text;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using System.Xml;
using System.Configuration;
using System.Data.SqlClient;

public class Default : IHttpHandler
{
    public void ProcessRequest (HttpContext context)
    {
        ....
        using (var conn = new SqlConnection(strSqlConnection))
        {
            conn.Open();
            using (var comm = new SqlCommand("....", conn, null))
            {
                    using (var reader = comm.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            context.Response.Write(reader["field"]+"<br>");
                        }
                    }
            }
        }
    }      

    public bool IsReusable
    {
        get { return true; }
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question