|
Source Code - Coding Syntax |
Question: Here in this article i have discuss How to Send Mail in ASP.NET(using C#) and also to use Session in asp.net and given a simple example of session after that i have discuss all the method to transfer value from one page to another page just like with the help of Querystring,cookies and context here i have also explain how to use Response.Redirect and Server.Transfer ?
Answer: First of All Explain how to Send Mail in ASP.NET:-
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
private void Page_Load(Object sender, EventArgs e)
{
try
{
MailMessage mailObj = new MailMessage();
mailObj.From = "dotnet@dotnetquestion.info.com";
mailObj.To = "info@dotnetquestion.info";
mailObj.Subject = "Hi jobs in DotNet";
mailObj.Body = "Are you a knowledge Seeker ";
mailObj.BodyFormat = MailFormat.Text;
SmtpMail.SmtpServer = "mail-fwd";
SmtpMail.Send(mailObj);
Response.Write("Mail sent successfully");
}
catch (Exception x)
{
Response.Write("Your message was not sent: " + x.Message);
}
}
Here I have used Query string
(i)Querystring doesnot suitable for important information not for security purpose becuase data comes with the Url so not Usefull where we have to secure data from the user.
Entry in Source Page:-
Response.Redirect("WebForm1.aspx?Id=" +idvalue) (In VB.NET)
Response.Redirect("WebForm1.aspx?Id=" +idvalue); (In C#.NET)
Entry in Desination page or in WebForm page to get the value we use this:-
Request.Querystring["id"]; (In C#.NET)
Request.Querystring("id"); (In VB.NET)
we get the value of querystring.
Here I have Disclose how to use Session
ASP.NET session state enables you to store and retrieve values for a user as the user navigates the different ASP.NET pages.ASP.NET session state is enabled by default for all ASP.NET applications.
Entry in Page Where we have to start our session:-
Session("Name")="value" (In VB.NET)
Session["Name"]="value"; (In C#.NET)
Entry in Desination page or in WebForm page to get the value from session:-
Dim name as string=Session("Name").ToString() (In VB.NET)
String name=Session["Name"].ToString();
Here I have Disclose how to use Cookies
A cookie is stored on the client's machine by their web browser software. To set a cookie, we include information in an HttpResponse that instructs the browser to save a cookie on the client's system. Here's the basic code for writing a Cookie in ASP.NET.
Entry to create a Cookies:-(in VB.NET)
Dim newCookie As HttpCookie = New HttpCookie("DotNet")
newCookie.Values.Add("Name", value)
newCookie.Values.Add("FavBook", value)
newCookie.Expires = #12/31/2007#
Response.Cookies.Add(newCookie)
Entry in Desination where we have to used cookies:-(in VB.NET)
Request.Cookies("Books")("Name")
Request.Cookies("Books")("FavBook")
|