web stats analysis

ASP.NET Archive

It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level.

It is an error to use a section registered as allowDefinition=’MachineToApplication’ beyond application level.
This error can be caused by a virtual directory not being configured as an application in IIS.

To resolve it, Right Click on the virtual directory – select properties and then click on “Create” next to the “Application” Label and the text box. It will automatically create the “application” using the virtual directory’s name. Now the application can be accessed.

When you have sub-directories in your application, you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or session state is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point).

You may get this error when trying to browse an asp.net application. The debug information shows that “This error can be caused by a virtual directory not being configured as an application in IIS.” However, this error occurs primarily out of 2 scenarios.

1. When you create an new web application using visual studio.net, it automatically creates the virtual directory and configures it as an application. However, if you manually create the virtual directory and it is not configured as an application, then you will not be able to browse the application and may get the above error. The debug information you get as mentioned above, is applicable to this scenario. To resolve it, Right Click on the virtual directory – select properties and then click on “Create” next to the “Application” Label and the textbox. It will automatically create the “application” using the virtual directory’s name. Now the application can be accessed.

2. When you have sub-directories in your application, you can have web.config file for the sub-directory. However, there are certain properties which cannot be set in the web.config of the sub-directory such as authentication, session state (you may see that the error message shows the line number where the authentication or sessionstate is declared in the web.config of the sub-directory). The reason is, these settings cannot be overridden at the sub-directory level unless the sub-directory is also configured as an application (as mentioned in the above point). Mostly we have the practice of adding web.config in the sub-directory if we want to protect access to the sub-directory files (say, the directory is admin and we wish to protect the admin pages from unauthorized users). But actually, this can be achieved in the web.config at the application’s root level itself, by specifying the location path tags and authorization

Disabling the right click on images in asp.net.

How to disable right click on images in asp.net?

Add below script between head tag


<script language="JavaScript" type="text/javascript">

var msg = "Right click disable.";
function click(e) {
if (document.all) {
if (event.button == 2 || event.button == 3) {
alert(msg);
return false;
}
}
else {
if (e.button == 2 || e.button == 3) {
e.preventDefault();
e.stopPropagation();
alert(msg);
return false;
}
}
}
if (document.all) {
document.onmousedown = click;
}
else {
document.onclick = click;
}
</script>
}

Add below code between body tag


<div>

Right click on page

</div>

String was not recognized as a valid DateTime.

String was not recognized as a valid DateTime in asp.net.

String was not recognized as a valid DateTime in c#.

Using DateTime.ParseExact.

string strDate ="10/12/2012";

DateTime date = DateTime.ParseExact(strDate, "dd/MM/yyyy", null);

Cannot access a disposed object?

Following Solution:

The problem is when you close form that it can not be used anymore you have to reopened.The code you posted tries to stop closing and only hides your window.If you want to doing this then you must set cancel-property true.

Private void Max_FormClosing(object sender, FormClosingEventArgs e)  

{

this.Hide();

this.Parent = null;

Cancel=true;

}

How to replace spaces with underscores in asp.net?

How can I replace a space in a string with an underscore in C#?

Type following code in code behind.


protected void Page_Load(object sender, EventArgs e)

{

string text= "Good Morning";

Response.Write(Replace(text));

}

static string Replace(string t)

{

return System.Text.RegularExpressions..Regex.Replace(t, @"\s+", "_");

}

How to get Indian Rupee Symbol in C#.Net?

How to change the background color for an MDI parent form in Visual C#?

Follow below Steps:

Step:1-Create a new Visual C# Windows application.By default Form1 is created.
Step:2-Click the form -> on the View menu -> select Properties Window to view the properties for the form.
Step:3-Set BackColor property to the color that you want.
Step:4-Set the IsMDIContainer property to True.
Step:5-Set the WindowState property to Maximized.
Step:6-Then Double-click the form to view its code window.
Step:7-Copy the below code and paste into form’s load event.

MdiClient ctlMDI;

// Loop through all of the form's controls looking
// for the control of type MdiClient.
foreach (Control ctl in this.Controls)
{
   try
   {
      // Attempt to cast the control to type MdiClient.
      ctlMDI = (MdiClient) ctl;

      // Set the BackColor of the MdiClient control.
      ctlMDI.BackColor = this.BackColor;
   }
   catch (InvalidCastException exc)
   {
      // Catch and ignore the error if casting failed.
   }
}

// Display a child form to show this is still an MDI application.
Form2 frm = new Form2();
frm.MdiParent = this;
frm.Show();
Step:8-On the Project menu -> Add Windows Form.
Step:9-Accept the default name Form2.cs, and then click Open.
Step:10-Finally press F5 to run the application.
Note:-That the background color of the form changes to the color that the Application
Background color is set to in Control Panel.

Error:A potentially dangerous Request.Form value was detected from the client

Add below tag in your web.config file:-


<httpRuntime requestValidationMode="2.0" />

How to use XML?

What is XML?

XML stands for eXtensible Markup Language.
XML is designed to transport and store data.
XML is important to know, and very easy to learn.

Below, there is an example of xml for your better understanding.


<?xml version="1.0"?>
<note>
<to>Bhavesh</to>
<from>Prakash</from>
<heading>Little information</heading>
<body>Give respect take respect(code.top10idea)</body>
</note>

Error: The name ‘CommandType’ does not exist in the current context.

Error: The name ‘SqlDbType’ does not exist in the current context.

Add following namespace

using System.Data;