URL: Uniform Resource Identifier (Locator)
Every response contains a status code. The following are some pf the status code with its level number & meaning:
- 100 level: Informational (Continue)
This means server has received the request headers, and that the client should proceed to send the request body.
- 200 level: Successful (OK)
This request has succeeded, and the resulting resources (e.g. file or script output) is returned in the message body.
- 300 level : Redirection
Multiple choices: It indicates that the future action needs to be taken by user agent in order to fulfil the request. It indicates multiple options for the resource that the client may need to follow.
- 400 level: Client Error (401 == Bad request)
Client error.
- 404 level: Not found
The requested resource does not exist.
- 404.10: Request header too long.
- 404.13: Content length too large.
- 404.14: URL too long.
- 404.15: Query string too large.
- 500 level: Server Error (503 == Service Unavailable)
An unexpected server error. The most common cause is server side script that has bad syntax, fails, or otherwise cannot run correctly.
Step 1: Create an application Visual Studio 2013. Now add one web form with the following code (or you can drag drop controls from ToolBox also),
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="View_State.aspx.cs" Inherits="State_Mangement.View_State" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head runat="server">
- <title></title>
- </head>
-
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />
- </div>
- </form>
- </body>
- </html>
Step 2: Add code in page load & button click event as,
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- TextBox1.Text = "0";
- }
- }
- protected void Button1_Click(object sender, EventArgs e)
- {
- int click_Count = Convert.ToInt32(TextBox1.Text) + 1;
- TextBox1.Text = click_Count.ToString();
- }
Step 3: Now run our application & press F12, you will see the following,
In above image we can see HTTP Message contains URL, Address, Status Code, Request & Response headers.
Here you can see status
code 200.
Step 4: Now add two web forms, out of which one will take input from user in textbox & will pass text box values using query string to another form,
- <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Query_String_Form_1.aspx.cs" Inherits="State_Mangement.Query_String_Form_1" %>
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml">
-
- <head runat="server">
- <title></title>
- </head>
-
- <body>
- <form id="form1" runat="server">
- <div>
- First Name:
- <asp:TextBox ID="TextBox1" runat="server" Columns="50" Rows="5" TextMode="MultiLine">
- </asp:TextBox>
- <br />
- <br />
- <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
- </div>
- </form>
- </body>
-
- </html>
Step 5: Add the following code for first web form in code behind file & button click event,
- protected void Button1_Click(object sender, EventArgs e)
- {
- int total_chars = TextBox1.Text.Length;
- Response.Redirect("Query_String_Form_2.aspx?FirstName=" + TextBox1.Text);
- }
Add the following code for second web form in Page Load event,
- protected void Page_Load(object sender, EventArgs e)
- {
- string f_name = Request.QueryString["FirstName"].ToString();
- Label1.Text = f_name;
- }
Step 6: Now run the application. I have placed one debugger here to understand how many characters we are going to enter here.
Now our output will look like the following with status code.
Step 7: Now if I enter more characters then the following will be visible,
I have entered 2040 characters then you can see what happens in the output.
Here you can see status
code 404.15.
Step 8: Now add another web form & take one button from tool box & add code on button click as in the following code snippet,
- protected void Button1_Click(object sender, EventArgs e)
- {
- Response.Redirect("my_page.aspx");
- }
Step 9: Now run this web form
Click on button & see the output.
Here you can see status
code 404.
For more understanding you can download the code.
Summary:
This article will help fresher candidates to understand HTTP Message Format in ASP.NET MVC 5.