ASP.NET FAQ - Basic

How can I logout when using FormsAuthentication

VB.NET

FormsAuthentication.SignOut()

C#

FormsAuthentication.SignOut();
Permalink
How can I save images ?

You need a stream to read the response, WebResponse.GetResponseStream(), and a stream to write it to the hard drive. FileStream should do the trick. You’ll have to write to the filestream what you read from the response stream.

Permalink
How to grab the referring URL

VB.NET

Response.Write ( Request.UrlReferrer.ToString())

C#

Response.Write ( Request.UrlReferrer.ToString());
Permalink
Can two different programming languages be mixed in a single ASPX file?

No. ASP.NET uses parsers to strip the code from ASPX files and copy it to temporary files containing derived Page classes, and a given parser understands only one language

Permalink
Is it possible to use a style sheet class directly on a control instead of using inline or page-level formatting ?

Every WebControl derived control has a CssClass property which allows you to set it’s format to a style sheet.

Permalink
Does ASP.Net still recognize the global.asa file?

ASP.Net does not recognize the standard ASP global.asa file. Instead it uses a file named global.asax with the same – plus additional – functionality.

Permalink
How to Compare time

VB.NET

Dim t1 As String = DateTime.Parse('3:30 PM').ToString('t')
Dim t2 As String = DateTime.Now.ToString('t')
If DateTime.Compare(DateTime.Parse(t1), DateTime.Parse(t2)) < 0 Then
	Response.Write(t1.ToString() & ' is < than ' & t2.ToString())
Else
	Response.Write(t1.ToString() & ' is > than ' & t2.ToString())
End If

C#

string  t1    = DateTime.Parse('3:30 PM').ToString('t');
string t2  = DateTime.Now.ToString('t');
if (DateTime.Compare(DateTime.Parse (t1), DateTime.Parse (t2)) < 0 )
{
	Response.Write(t1.ToString() + ' is < than ' + t2.ToString());
}
else
{
	Response.Write(t1.ToString() + ' is > than ' + t2.ToString());
}
Permalink
How to get the IP address of the host accessing my site

VB.NET

Response.Write  (Request.UserHostAddress.ToString ())

C#

Response.Write  (Request.UserHostAddress.ToString ());
Permalink
How to prevent a button from validating it’s form

Set the CauseValidation property of the button control to False

Permalink
What is the equivalent of date() and time() in ASP.NET

VB.NET

System.DateTime.Now.ToShortDateString()
System.DateTime.Now.ToShortTimeString()

C#

System.DateTime.Now.ToShortDateString();
System.DateTime.Now.ToShortTimeString();
Permalink
How to find out what version of ASP.NET I am using on my machine?

VB.NET

Response.Write(System.Environment.Version.ToString() )

C#

Response.Write(System.Environment.Version.ToString() );
Permalink