Welcome to RP's venture...Here you can find some of the relative topics like ASP.Net, C#.Net,VB.Net, SQL Server, AJAX, Javascripts, Sharepoint, WPF, WCF, Silverlight, MVC, General knowledge, Jokes, Fun, Technical, Non-Technical etc.
0

IIS Redirects - 301 , 302

Posted by Rajendra Prasad Panchati on Friday, July 23, 2010

Microsoft's Internet Information Server ( MS IIS ) is very different from Apache, and you need to handle redirects on it differently.
Although you can use the popular FrontPage web development software with Apache + FP extensions, most people who use FrontPage prefer to use IIS. Also, Microsoft's .NET and ASP development platforms usually work best on MS IIS (no surprise there).
Definitions for Terms used in this Article

Detailed Information

Overview

What you are trying to accomplish here is to have one resource (either a page or an entire site) redirect a visitor to a completely different page or site, and while doing so tell the visitor's browser that the redirect is either permanent (301) or temporary (302).
Therefore you need to do three things:
  1. Have 2 resources - one source page or website, and one destination page or website.
  2. When an attempt to access the source resource is made, IIS transfers the visitor to the destination instead.
  3. During the transfer, IIS reports to the visitor that a redirect is happening and it's either temporary or permanent.
The good news is that IIS has always supported this, and you can use it's control panel to make the redirect.

Administrator Mode - Redirecting a Domain

If you can log into the Windows 2000 (or higher) server and access the desktop, then choose:
Start > Programs > Administrative Tools > Internet Services Manager
Now choose the server running the site you want to forward. Remember you need 2 sites - one to forward FROM and one to forward TO. These can be on the same, or separate servers.

Right click on the site you want to redirect FROM and choose Properties > Home Directory

You will see the following:


The default is the first choice, "A directory located on this computer". Change it to "A redirection to a URL" and type in the new URL.
If you want it to be a 301, then be sure to check ON the choice for "A permanent redirection for this resource". If you want it to be a 302, leave the choice checked OFF.

Administrator Mode - Redirecting an Individual Page

If you can log into the Windows 2000 (or higher) server and access the desktop, then choose:
Start > Programs > Administrative Tools > Internet Services Manager
Now choose the server running the site you want to forward. Choose the site with the webpage you want to forward in it, then right click on the it and choose "Properties".

You will see the following:


The default is the first choice, "The designated file". Change it to "A redirection to a URL" and type in the new URL.
If you want it to be a 301, then be sure to check ON the choice for "A permanent redirection for this resource". If you want it to be a 302, leave the choice checked OFF.
If you don't control the IIS server, ask the admin to do the above. Done.

Passing on Variables or a Query String During IIS Redirects

Let's say that you want to pass on some variables, for example, you wanted to redirect an ASP site that accepted arguments for some pages and pass those same arguments on to the same pages at the new site.
In this case, in the "Redirect to:" box, enter the domain you wish to move to (no trailing slash), plus $S$Q .
For example:
http://www.newdomain.com$S$Q
Next, check the options that state the client will be sent to "The exact URL entered above", as well as "A permanent redirection for this resource" (if you want it to be a 301). Done.
What does this $S$Q do? These are tags that IIS will automatically replace - $S will be replaced with the subdirectory location (such as /shopping/cart.aspx) and $Q will be replaced with the querystring (such as ?id=Blue).
Server Variable Function Example
$P Passes parameters that were passed to the URL to the new URL. If the request contains parameters such as http://www.oldsite.com/cart.asp?id=Blue , then $P would represent all the values after the question mark in the URL, example $P would equal id=Blue (no question mark).
$Q Passes the parameters including the question mark. This is the same as $P but includes the question mark or query string. So $P would equal ?id=Blue
$S Passes the matching suffix of the URL to the new URL. If the request is for http://www.oldsite.com/shopping/cart.asp, then $S represents /cart.asp. If the request was for http://www.oldsite.com/shopping then the value of $S would be /shopping
$V Removes the server name from the original request. If the request is for http://www.oldsite.com/shopping/cart.asp then $V would contain everything after the server name, eg: /shopping/cart.asp.
* Wildcard symbol used for replacement. Let's say you want to redirect all requests for html pages to a single asp page - you could do so in the following way: *;*.htm;page.asp

This works for both Site Redirects and Individual Page Redirects.

Common Scenarios

I Just Want To Switch Domains!

This is actually pretty straightforward. You can tweak things to get exactly what you need with the variables above, but the following will work for the most common setups:
http://www.newdomain.com$V$Q
Do NOT add a trailing slash "/" at the end of the domain name!
Make sure you check:
  • The exact URL entered above
  • A permanent redirection for this resource
Done! This will send everything after the old domain name to the new domain name, including variables. You need to do is make sure that the new website is set up exactly the same as the old one and that all you are doing is changing domain names.

Non-WWW to WWW Redirect for IIS

When you set up a site in IIS, usually you set up the site with a domain name and add the domain name with both versions, www and non-www, to the host headers for the account. This creates a potential duplication issue, though.
The better way to do this is to actually create 2 accounts - one with the www version and one without. Then you put the website in your preferred version and a single page in the other. Normally, you would then treat this as if you were switching domains (above), with the 2 domains being the www and the non-www versions.
Another method, for those that don't have direct access to the control panel (common with many ISP's/ hosts), is to put your entire website in the www account and then a single page in the non-www account. Then you would put the following code in the default page in the account with the single page (i.e. the one you are redirecting):
< %@ Language=VBScript %>
< %
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", http://www.example.com
%>

What about Parameters?

If you do a non-www to www redirect for MS Internet Information Services (IIS) and have parameters that need to be passed on, then do the following (Thanks to Chris Hirst for testing this):
  1. Do the above non-WWW to WWW redirect
  2. Make double sure that you do NOT have a trailing slash at the end of the domain (http://www.newdomain.com$V$Q, NOT http://www.newdomain.com/$V$Q)
  3. As with all these redirects, make sure that you check "The exact URL entered above"

Don't Have Administrator or Desktop Access?

If possible, ask the Administrator for the site to perform the above steps. If you can't, you need to use ASP or .NET scripting on-page to do redirects.

Conclusion

IIS is a powerful and easy to use web hosting platform. If you have access to the Admin panel you can accomplish basic tasks (like simple redirection) easily and quickly. If you don't have access (and don't want to switch hosts) then you will have to use redirection scripting to accomplish this. You'll learn more about that in the Redirects Using On-Page Scripting and Headers section.

Reference: http://www.mcanerin.com/en/articles/301-redirect-iis.asp

|
0

ASP.NET Validator Controls

Posted by Rajendra Prasad Panchati on Friday, July 16, 2010
This tutorial gives a brief overview of how to use the ASP.NET Input Validation Controls.

Back when we had only ASP, developers who had to write webpages for forms knew that the most tedious part is writing code to validate the user input. User input had to be validated so that malicious use of the pages couldn't be achieve. User input had to be validated so that an incorrect piece of information would not be entered. User input had to be validated so that the information stored was standardized. Yeah, some people had libraries of ASP functions to validate common things such as postal codes (zip codes for you Americans), e-mail addresses, phone numbers, etc. The developers of ASP.NET saw the tedium in always having to check user input. They decided that to simplify our life by including validation controls.
ASP.NET validation controls also provide two ways of validation: Server-side or Client-side. The nice thing about these Validation controls is that it will preform client-side validation when it detects the browser is able (unless client-side validation has been disabled). Thus reducing roundtrips. And it will preform server-side where necessary. This client-side/server-side detection and validation is done without extra work by the developer!

With ASP.NET, there are six(6) controls included. They are:

  • The RequiredFieldValidation Control
  • The CompareValidator Control
  • The RangeValidator Control
  • The RegularExpressionValidator Control
  • The CustomValidator Control

Validator Control Basics
All of the validation controls inherit from the base class BaseValidator so they all have a series of properties and methods that are common to all validation controls. They are:

  • ControlToValidate - This value is which control the validator is applied to.
  • ErrorMessage - This is the error message that will be displayed in the validation summary.
  • IsValid - Boolean value for whether or not the control is valid.
  • Validate - Method to validate the input control and update the IsValid property.
  • Display - This controls how the error message is shown. Here are the possible options:
    • None (The validation message is never displayed.)
    • Static (Space for the validation message is allocated in the page layout.)
    • Dynamic (Space for the validation message is dynamically added to the page if validation fails.)


The RequiredFieldValidation Control
The first control we have is the RequiredFieldValidation Control. As it's obvious, it make sure that a user inputs a value. Here is how it's used:

Required field: <asp:textbox id="textbox1" runat="server"/>
<asp:RequiredFieldValidator id="valRequired" runat="server" ControlToValidate="textbox1"
    ErrorMessage="* You must enter a value into textbox1" Display="dynamic">*
</asp:RequiredFieldValidator>
>

In this example, we have a textbox which will not be valid until the user types something in. Inside the validator tag, we have a single *. The text in the innerhtml will be shown in the controltovalidate if the control is not valid. It should be noted that the ErrorMessage attribute is not what is shown. The ErrorMessage tag is shown in the Validation Summary (see below).

The CompareValidator Control
Next we look at the CompareValidator Control. Usage of this CompareValidator is for confirming new passwords, checking if a departure date is before the arrival date, etc. We'll start of with a sample:

Textbox 1: <asp:textbox id="textbox1" runat="server"/><br />
Textbox 2: <asp:textbox id="textbox2" runat="server"/><br />
<asp:CompareValidator id="valCompare" runat="server"
    ControlToValidate="textbox1" ControlToCompare="textbox2"
    Operator="Equals"
    ErrorMessage="* You must enter the same values into textbox 1 and textbox 2"
    Display="dynamic">*
</asp:CompareValidator>
>

Here we have a sample where the two textboxes must be equal. The tags that are unique to this control is the ControlToCompare attribute which is the control that will be compared. The two controls are compared with the type of comparison specified in the Operator attribute. The Operator attribute can contain Equal, GreterThan, LessThanOrEqual, etc.
Another usage of the ComapareValidator is to have a control compare to a value. For example:

Field: <asp:textbox id="textbox1" runat="server"/>
<asp:CompareValidator id="valRequired" runat="server" ControlToValidate="textbox1"
    ValueToCompare="50"
    Type="Integer"
    Operator="GreaterThan"
    ErrorMessage="* You must enter the a number greater than 50" Display="dynamic">*
</asp:CompareValidator>
>

The data type can be one of: Currency, Double, Date, Integer or String. String being the default data type.

The RangeValidator Control
Range validator control is another validator control which checks to see if a control value is within a valid range. The attributes that are necessary to this control are: MaximumValue, MinimumValue, and Type.
Sample:

Enter a date from 1998:
<asp:textbox id="textbox1" runat="server"/>
<asp:RangeValidator id="valRange" runat="server"
    ControlToValidate="textbox1"
    MaximumValue="12/31/1998"
    MinimumValue="1/1/1998"
    Type="Date"
    ErrorMessage="* The date must be between 1/1/1998 and 12/13/1998" Display="static">*</asp:RangeValidator>
>


The RegularExpressionValidator Control
The regular expression validator is one of the more powerful features of ASP.NET. Everyone loves regular expressions. Especially when you write those really big nasty ones... and then a few days later, look at it and say to yourself. What does this do?
Again, the simple usage is:

E-mail: <asp:textbox id="textbox1" runat="server"/>
<asp:RegularExpressionValidator id="valRegEx" runat="server"
    ControlToValidate="textbox1"
    ValidationExpression=".*@.*\..*"
    ErrorMessage="* Your entry is not a valid e-mail address."
    display="dynamic">*
</asp:RegularExpressionValidator>
>

Here is a webpage I like to use to check my regular expressions.

The CustomValidator Control
The final control we have included in ASP.NET is one that adds great flexibility to our validation abilities. We have a custom validator where we get to write out own functions and pass the control value to this function.

Field: <asp:textbox id="textbox1" runat="server">
<asp:CustomValidator id="valCustom" runat="server"
    ControlToValidate="textbox1"
    ClientValidationFunction="ClientValidate"
    OnServerValidate="ServerValidate"
    ErrorMessage="*This box is not valid" dispaly="dynamic">*
</asp:CustomValidator>
>

We notice that there are two new attributes ClientValidationFunction and OnServerValidate. These are the tell the validation control which functions to pass the controltovalidate value to. ClientValidationFunction is usually a javascript funtion included in the html to the user. OnServerValidate is the function that is server-side to check for validation if client does not support client-side validation.
Client Validation function:


&ltscript language="Javascript">
<!--
    /* ... Code goes here ... */
-->
</script>
>

Server Validation function:


Sub ServerValidate (objSource As Object, objArgs As ServerValidateEventsArgs)
    ' Code goes here
End Sub
b


Validation Summary
ASP.NET has provided an additional control that complements the validator controls. This is the validation summary control which is used like:

<asp:ValidationSummary id="valSummary" runat="server"
    HeaderText="Errors:"
    ShowSummary="true" DisplayMode="List" />
>

The validation summary control will collect all the error messages of all the non-valid controls and put them in a tidy list. The list can be either shown on the web page (as shown in the example above) or with a popup box (by specifying ShowMessageBox="True")

Now you know how to use the Validator Controls in ASP.NET! Have fun!
I will also upload a sample of all the validator controls to the code sample section.

Acknoledgment: Professional ASP.NET (published by Wrox) was used a reference. It's a good book!

Tips to remember

  • If you are doing server-side validation, make sure the button onclick method has a Page.IsValid if statement or it will look like your validators aren't doing anything
  • Don't forget to wrap everything in the <form runat=server> tag. 

Reference : http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=46

|
0

Web Service creation in ASP.Net

Posted by Rajendra Prasad Panchati on Wednesday, July 07, 2010

|
0

Round Edged div

Posted by Rajendra Prasad Panchati on Wednesday, July 07, 2010
<div style="border: medium none ; height: 50px; background-color: #FDE9B4; font-size: 0pt; float: left; width: 100%; position: relative;" >
<div style="margin: 0px 0px -7px;">
           
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 3px; overflow: hidden; height: 1px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 2px; overflow: hidden; height: 1px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 1px; overflow: hidden; height: 2px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 0px; overflow: hidden; height: 3px; background-color: transparent;"></div>
</div>
           
<div style="font-size:12px;text-align:centre;">

Your Text Here

</div>

<div id="searchBoxBottomRound" style="display: block; margin: 0pt; padding: 0pt; position: absolute; left: 0pt; bottom: 0pt; width: 100%;">
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 0px; overflow: hidden; height: 3px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 1px; overflow: hidden; height: 2px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 2px; overflow: hidden; height: 1px; background-color: transparent;"></div>
<div style="border-style: none solid; border-color: #FFFFFF; border-width: 0pt 3px; overflow: hidden; height: 1px; background-color: transparent;"></div>

</div>
</div>

|

About Me