Communications with Web Browser; Response Object

Response object वह है जिससे आपका server code browser को वापस बात करता है: यह content को page में लिख सकता है, visitor को दूसरे page पर भेज सकता है, और cookies set कर सकता है, हर request-response round trip का outgoing half।

9 min read · 7 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

Conversation का Server वाला Side

हर page view एक छोटी conversation है: browser एक request भेजता है, और server एक response भेजता है। आप हमेशा से response build करते आए हैं (server controls इसमें render होते हैं), पर कभी-कभी आपके code को browser से directly बात करनी पड़ती है, एक quick message भेजने के लिए, या visitor को कहीं और redirect करने के लिए।

ASP.NET exactly इसके लिए आपको Response object देता है: exchange का outgoing half। यह lesson cover करता है आपका server code Response को browser से communicate करने के लिए कैसे इस्तेमाल करता है, और इसके incoming partner, Request को।

Theory

Response Object

Response वह reply represent करता है जो आपका server browser को वापस भेज रहा है। इसके सबसे useful members:

  • Response.Write(text): text को सीधा page output में लिखता है।
  • Response.Redirect(url): browser को एक अलग page पर जाने के लिए कहता है।
  • Response.Cookies: response को cookies attach करता है (browser में stored छोटा data)।

इसका partner Request है, browser से incoming data: Request.QueryString URL से values पढ़ता है, Request.Form submitted form fields पढ़ता है, Request.Cookies browser ने भेजी cookies पढ़ता है। Request आता है; Response जाता है।

Practical

Writing to the browser and redirecting

// Send text straight into the page
Response.Write("Welcome to FestConnect!");

// After a successful registration, send the student to a thank-you page
protected void btnRegister_Click(object sender, EventArgs e)
{
    // ... save the registration ...
    Response.Redirect("ThankYou.aspx");   // browser now requests ThankYou.aspx
}

// Read something the browser sent in (the incoming Request):
string eventId = Request.QueryString["eventId"];   // from a URL like ?eventId=12

Formula

Request In, Response Out

इस pairing को hold कीजिए। Request वह सब कुछ है जो browser ने server को TO भेजा: URL, query string, form fields, cookies। Response वह सब कुछ है जो server BACK भेजता है: HTML, redirects, store करने के लिए cookies।

आपका code Request से पढ़ता है यह जानने के लिए visitor क्या चाहता है, और reply करने के लिए Response में लिखता है। हर ASP.NET page इन दोनों के बीच बैठता है: एक तरफ़ incoming Request, दूसरी तरफ़ outgoing Response।

Quiz

एक student register होने के बाद, आप चाहते हैं इनका browser ThankYou.aspx पर move हो। आप कौन सा Response member इस्तेमाल करते हैं?

  1. Response.Write("ThankYou.aspx"), जो page पर navigate करता है
  2. Response.Redirect("ThankYou.aspx"), जो browser को उस page request करने के लिए कहता है
  3. Request.QueryString["ThankYou.aspx"], जो page load करता है
  4. Response.Cookies, जो एक cookie इस्तेमाल करते हुए redirect करता है
Show the answer

Response.Redirect("ThankYou.aspx"), जो browser को उस page request करने के लिए कहता है

Response.Redirect(url) browser को एक अलग page request करने के लिए कहता है, जो exactly है कैसे आप visitor को ThankYou.aspx पर move करते हैं। Option A wrong है: Response.Write बस current page पर text 'ThankYou.aspx' print करता है; यह कहीं navigate नहीं करता। Option C wrong है: Request.QueryString URL से incoming values READS करता है; यह incoming Request का हिस्सा है, browser को कहीं भेजने का तरीका नहीं। Option D wrong है: Response.Cookies browser में छोटा data store करता है; यह redirection perform नहीं करता। Direction याद रखिए: browser को एक नए page पर भेजने के लिए, Response.Redirect इस्तेमाल कीजिए।

Think first

बस Thank-You Content दिखाने की बजाय Redirect क्यों?

आप registration page पर सीधा thank-you message display कर सकते थे। इसकी बजाय एक separate page पर एक redirect क्यों भेजें? फिर tap कीजिए।

Show the answer

Main reason DOUBLE-SUBMIT problem avoid करना और एक clean URL देना है। अगर आप registration save करें और फिर same page पर बस एक thank-you message दिखाएँ (जो एक POST से पहुँचा गया था), browser अभी भी 'remember' करता है कि यह form submit करके यहाँ पहुँचा। अगर student फिर refresh करे, browser form को re-submit करता है, इन्हें दूसरी बार register करते हुए, और एक scary 'resend form data?' prompt दिखाता है। एक successful save के बाद redirect करना (Post-Redirect-Get नाम का एक pattern) इसे fix करता है: save होने के बाद, आप browser को एक fresh GET request के साथ ThankYou.aspx भेजते हैं, तो refresh करना बस harmless thank-you page reload करता है, कभी re-submit नहीं करता। यह visitor को form के URL की बजाय एक sensible, bookmarkable URL पर भी छोड़ता है। तो redirecting सिर्फ़ cosmetic नहीं है; यह accidental duplicate actions रोकता है और navigation clean रखता है। Save कीजिए, फिर redirect कीजिए: एक habit जो रखने लायक है।

Summary

Key takeaways

  • हर page view एक Request (browser से incoming) और एक Response (server से outgoing) है।
  • Response object वह है जिससे आपका server code browser को वापस बात करता है।
  • Response.Write text को page में भेजता है; Response.Redirect browser को एक अलग URL पर भेजता है; Response.Cookies browser में data store करता है।
  • इसका partner Request incoming data पढ़ता है: Request.QueryString (URL values), Request.Form (submitted fields), Request.Cookies।
  • Visitor क्या चाहता है सीखने के लिए Request से पढ़िए; reply करने के लिए Response में लिखिए।
  • एक successful action के बाद, redirecting (Post-Redirect-Get) refresh पर duplicate submissions avoid करता है और एक clean URL रखता है।
  • Memory hook: Request in, Response out।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Database Access and Client-Server Communications

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Communications with Web Browser; Response Object · .NET Technology (Major-13) · Gri-Learn