Java/C# code example

N

Nicholas Potts

Hi, I'm trying to findout the equivalent code in C# for the following
Java example that extracts information from an HTTP request header.


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BasicServlet extends HttpServlet {
throws IOException {

PrintWriter out = res.getWriter();

out.println("<html>");
out.println("<body>");
out.println("<p>");

String name = req.getParameter("name");
if (name != null)
out.println("Hello" + name);
else
out.println("Hello anonomous user");

out.println("</p>");
out.println("</body>");
out.println("</html>");


can anyone help?
 
N

Nicholas Paldino [.NET/C# MVP]

Nicholas,

The Java Servlet model and the ASP.NET model are different, to say the least. In ASP.NET, what you want to go is get the HttpRequest instance that corresponds to the request. You can then use the QueryString property to get the values in the query string that were sent to to the server.

To get the request (from anywhere), you can use the static Current property on the HttpContext class to get the current context. From there, you can use the Request property to get the request.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top