Friday, April 25, 2008

Web.config for VS2005 is rejected by IIS as Badly Formed

I created a very simple website using VS .NET 2005. When I am trying to bring up my web page, I keep getting the following error message as shown below.


Server Error in '/APS_WebSetup' Application. ________________________________________
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Unrecognized configuration section 'xhtmlConformance'

Source Error:

Line 89: -->
Line 90: <globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
Line 91: <xhtmlConformance mode="Legacy"/>
Line 92: <pages>
Line 93: <namespaces>

Source File: C:\inetpub\wwwroot\APS_WebSetup\web.config Line: 91
________________________________________
Version Information: Microsoft .NET Framework Version: 1.1.4322.2407; ASP.NET Version: 1.1.4322.2407

************************************************************************************

Server Error in '/APS_WebSetup' Application. ________________________________________
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Child nodes are not allowed.

Source Error:

Line 91:
Line 92: <pages>
Line 93: <namespaces>
Line 94: <add namespace="Microsoft.VisualBasic"/>
Line 95: <add namespace="System.Data"/>

Source File: C:\inetpub\wwwroot\APS_WebSetup\web.config Line: 93
________________________________________
Version Information: Microsoft .NET Framework Version: 1.1.4322.2407; ASP.NET Version: 1.1.4322.2407

***********************************************************************************

These errors will occurred when I attempt to run an application developed using .NET framework 2.0 but Microsoft IIS web server defaults to an earlier version of the .NET framework, in my case is .NET 1.1.

To solve these errors, follow the steps as below:
1. Install .NET framework 2.0 (if it is not installed in your system).
2. Go to your IIS -> Default Web Site and select your virtual directory.
3. Right-click the virtual directory and click Properties.


4. Go to ASP .NET tab. Change the ASP .NET version to 2.0. Click Apply and OK.


Try to run the application again. The errors may solve now.

Hope this can help you all. Cheers!

Friday, April 18, 2008

PlaceHolder control in ASP .NET

PlaceHolder control acts as a container to store other web controls to a web page dynamically. It does not produce any output; its main function is used as a container for other controls. You can use the Controls.Controls collection to add, insert or remove controls from a PlaceHolder control.

Here is an example of how to add a web control to PlaceHolder control.

HTML
<form id="Form1" method="post" runat="server">
<asp:placeholder id="placeHolder" runat="server"> </asp:placeholder>
</form>


CODE BEHIND
Dim newLbl As New Label
newLbl.ID = "Label1"
newLbl.Text = "This is a label control. "
placeHolder.Controls.Add(newLbl)

Dim newBtn As New Button
newBtn.ID = "Button1"
newBtn.Text = "This is a button control. "
placeHolder.Controls.Add(newBtn)

' To remove the controls
placeHolder.Controls.Remove("Label1")
placeHolder.Controls.Remove("Button1")


Cheers!

Authentication and Authorization in ASP .NET

Authentication and authorization are two tightly-coupled concepts to form the core of security for .NET applications.

Authentication is the process of determining and verifying the identity of users based on the users’ credentials. Authorization is the process of determining what level of access an authenticated identity should be granted to a given resource.

Whenever a user logs on to a system, he/she will be authenticated first before he/she is authorized.

Authentication
There are three types of authentication in ASP .NET:
1. Form authentication
2. Windows authentication
3. Passport authentication

Form Authentication
You can handle authentication using your own custom logic depends on code written in your .NET application. After a user is authenticated, the credentials will be stored in a cookie to handle subsequent processes.

Windows Authentication
Windows authentication is the default authentication mode in ASP .NET. By using this mode, a user is authenticated based on his/her Windows account. There are four types of Windows authentication methods:
1. Anonymous Authentication – IIS allows any user
2. Basic Authentication – windows username and password (credentials) has to be sent across the network in plain text format, which is insecure.
3. Digest Authentication – same as Basic Authentication but the credentials are encrypted.
4. Integrated Windows Authentication – Depend on Kerberos technology, with strong credential encryption.

Passport Authentication
Passport authentication uses Microsoft’s passport service to authenticate users in a .NET application. Passport uses an encrypted cookies mechanism to identify an authenticated user. If a user had signed in the passport when they browse to your application, he/she will be considered as authenticated by ASP .NET. Else they will be redirected to the passport login page.

Authorization
There are two types of authorization in ASP .NET:
1. URL authorization – specify authorization rules in web.config for different web URLs
2. File authorization - relying on the NTFS system for granting permission

Both authentication and authorization is specified in the web.config of the application.

Example in web.config

<configuration>
    <system.web>

        <authentication mode="[Windows/Forms/Passport/None]" >
        </authentication>

        <authorization>
            <allow users="July"/>
            <deny users="August"/>
            <deny users="?"/>
        </authorization>

    </system.web>
</configuration>

Wednesday, April 16, 2008

Differences between SqlDataAdapter and SqlDataReader

When I went for an interview last few weeks, the interviewers threw me some technical questions about .NET. Luckily I still can get some correct ideas on those questions. Here I will share with you one of the interview questions "What is the differences between SqlDataAdapter and SqlDataReader?"

For SqlDataReader, you need to call the ExecuteReader method of the SqlCommand object.

You can use SqlDataReader when your data access operations is mainly for fetching and displaying all the records in the database, which does not involve insert, update or delete actions, and other manipulations actions e.g. forward-only and read-only.

If the data from database is mainly for displaying in data grid, labels or other web controls, you can go for SqlDataReader.

However, when the SqlDataReader is in use, it requires the connection with the database remains open until its operation is completed.

In short, SqlDataReader can be used when:
- To deal with large volumes of data
- To optimize data access
- To display data in web controls (no update/insert/delete action)


SqlDataAdapter acts as a bridge between a dataset and database server for fetching and saving data. If your data access operations involve actions other than only displaying data, you can use SqlDataAdapter to generate a dataset or datatable.

By using SqlDataAdapter, you don’t need to explicitly open the connection. It will open and close the connection automatically when required.

One of the advantages is that the dataset works on a disconnected architecture. The connection does not need to be remained for it to perform manipulations or other actions. The connection is only required when there is an update records to the database server.

Hope you can get some ideas about SqlDataReader and SqlDataAdapter.

Saturday, April 12, 2008

Disable Right-Click for Your Website

NO RIGHT-CLICK for Images
Have you ever tried so hard on your website to stop someone stolen your graphics as their own.

Here is an extra step in protecting your graphics/images from being saved. But there is no foolproof method to stop someone from copy your images. If they really want something from your web site, they can find ways around it. But at least you can eliminate some proportion of visitors stealing images from your web site.

It is very simple. Whenever someone right clicks his/her mouse, a message will popped up to show him/her that he/she do not have permission to do so. Place the script below within the head tags of your html.

<script language="JavaScript">
<!--
var msg="Right-click is disabled!";

function rightclick(go) {
    if (document.all) {
        if (event.button == 2) {
            alert(msg);
            return false;
        }
    }
    if (document.layers) {
        if (go.which == 3) {
            alert(msg);
            return false;
        }
    }
}
if (document.layers) {
    document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=rightclick;
// -->
</script>


NO RIGHT-CLICK for Sources
To protect the whole page of your web site, copy and paste the script below within your head tags in your html.

<script language="JavaScript">
<!--
function rightclick(e) {
    if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2))
        return false;
    else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
        alert('Right-click is disabled!');
        return false;
    }
    return true;
}

document.onmousedown=rightclick;
document.onmouseup=rightclick;
if(document.layers) window.captureEvents(Event.MOUSEDOWN);
if(document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=rightclick;
window.onmouseup=rightclick;
//-->
</script>

Tuesday, April 1, 2008

Remove a Visual Studio from Source Control

To remove an item from source control, the first thing that you need to do is to select all items in your project and uncheck the Read-Only property. Click Apply then OK. Do these steps for both folder of your project (MyDocuments\Visual Studio Projects and wwwroot).


In your Solution Directory, delete all the files with the extension .vssscc or .scc (includes all child folders in your solution directory).

Next, right click on your .sln file and select Open with… Select Notepad.

In your .sln file, find the GlobalSection(SourceCodeControl) = preSolution part. Select the whole part of it until EndGlobalSolution and remove it. Save and close the file.


For each of the .vbproj in your project, open it with Notepad. Under <VisualBasic> you can find the following attributes: SccProjectName, SccLocalPath, SccAuxPath, and SccProvider as shown below. Remove it, save and close the file.


Now, the source control had completely removed from the project.

Hope you will find this helpful.
 

Get paid for your opinions! Click on the banner above to join Planet Pulse. Its totally free to sign up, and you can earn UNLIMITED. Find out more by visiting PLANET PULSE.
July Code Blog Copyright © 2010 Blogger Template Designed by Bie Blogger Template