Beruflich Dokumente
Kultur Dokumente
1.1 Why are Server control tags shown in the browser instead of the controls
it represents?
This is because the server control tags were not converted into their respecting HTML element tags by ASP.Net. This
.Net framework provides an Administration utility that manages the installation and uninstallation of multiple
C:\WINNT\Microsoft.NET\Framework\v**\aspnet_regiis.exe
1.2 How To Repair ASP.Net IIS Mapping After You Remove and Reinstall IIS?
To reassociate aspx file extensions with ASP.Net runtime, you'll have to run the utlity aspnet_regiis.exe -i
1.3 Why do I get "HTTP 500" error (or "(DLL) initialization routine failed") in
my browser?
This is because if you have the /3GB boot switch enabled, the ASP.NET worker process (Aspnet_wp.exe) does not
start. For more information see Microsoft Knowledge Base Article - 320353
To create and set the "ASPNETENABLE3GB" environment variable as mentioned in the above article, right click
MyComputer ->Properties->Advanced > Environment Variables > System variables > New.
Add the variable name in the top text box and the value in the lower textbox.
You have to enable the ASP.NET in the Web Server Extensions list
From Start -> Settings -> Control Panel -> Administrative Tools -> double click IIS Manager.
Go to the Web Service Extensions tab, click Active Server Pages, then press the "Allow" button on the left.
1.5 What are the Best practices for side-by-side execution of Framework 1.0
and 1.1?
In ASP.NET, applications are said to be running side by side when they are installed on the same computer, but use
different versions of the .NET Framework. The following article at www.asp.net details the practices that are
1.6 Can I have VS.NET and the Visual Studio 6.0 installed on the same
machine?
Yes! VS.Net works with the .Net framework, while VS6.0 works with MFC or the Windows API directly, for the most
part. They can be installed and run on the same machine without any considerations.
To verify if IIS is installed, go to your 'Add or Remove Programs' utility in the Control panel and click on the
On XP Pro and below, you should see an item called "Internet Information Services (IIS)". If this is checked, IIS
should be installed.
On Win2K3, you'll see "Application Server". If this is checked, select it and then click 'Details'. Another form
should open which will contain "Internet Information Services (IIS)". If it is checked, IIS should be installed.
1.8 In Visual Studio .NET, how do I create a new ASP.NET application for an
existing ASP.NET project?
First create an IIS application using the IIS MMC. Then in Visual Studio .NET, use the "New Project In Existing
Folder" project template (at the end of the template list). It will first ask you for the project name (use the same
one you created for the IIS application). Click OK button. Then enter in physical folder location.
1.9 Why do I get the error message "Server Application Unavailable The web
application you are attempting to access on this web server is currently
unavailable. Please hit the "Refresh" button in your web browser to retry
your request."?
By default, ASP.NET runs its worker process (Aspnet_wp.exe) with a weak account (the local machine account,
which is named ASPNET) to provide a more secure environment. On a domain controller or on a backup domain
controller, all user accounts are domain accounts and are not local machine accounts. Therefore, Aspnet_wp.exe
fails to start because it cannot find a local account named "localmachinename\ASPNET". To provide a valid user
account on the domain controller, you must specify an explicit account in the section of the Machine.config file, or
you must use the SYSTEM account. For more details : FIX: ASP.NET Does Not Work with the Default ASPNET
1.10 In Visual Studio .NET, how do I create a new ASP.NET application which
does not have a physical path under wwwroot?
You must first create an IIS application using the IIS MMC. Then in Visual Studio .NET, create a new ASP.NET
application and give it the same name you used for the IIS application
When you install the .Net framework on your web server, it installs some script files (including the above) under the
root folder (usually "C:\inetput\wwwroot" if you do a default installation) . You can then find the above file at
The above problem could happen if you reconfigured your web root directory to be a different one after you installed
ASP.Net in your web server. If that is the case, then run 'aspnet_regiis -c' (utility is under
%windir%\Microsoft.NET\Framework\v1.1.4322, for example) or copy over manually the above script files into a
similar sub-directory below your current web root directory. Also, if you look at the error message in detail, you will
1.12 After installing .NET Framework SP1 the client side validations, or rather
validator controls are not working?
The problem seems to be in the javascript file WebValidationUi.js in aspnet_client folder.The changes in that file
prevent a page to be submitted. That could be the reason your javascript validations are not working. As a
workaround, just copy the old WebValidateionUi.js over the new one.
2. In the Open text box, type cmd, and then click OK.
WindowsDirectory\Microsoft.NET\Framework\v1.0.3705\
aspnet_regiis -s W3SVC/1/ROOT/WebApp1
2. In the Open text box, type cmd, and then click OK.
WindowsDirectory\Microsoft.NET\Framework\v1.1.4322\
aspnet_regiis -s W3SVC/1/ROOT/WebApp2
Find the ASP.NET Version Used for the Application View the script map for an ASP.NET application to determine
the version of ASP.NET that the application uses. To view the script map for an ASP.NET application, follow these
steps:
2. Double-click Administrative Tools, and then double-click Internet Information Services (IIS).
3. Expand local computer, expand Web Site, and then expand Default Web Site.
5. Right-click the folder that contains the ASP.NET application, and then click Properties.
6. Click the Directory tab, and then click Configuration. The Application Configuration dialog box opens.
7. Click the Mappings tab, and then select an ASP.NET application extension, such as .asmx or .aspx. The
Executable Path column of the dialog box lists the path to the ASP.NET ISAPI version that the application
indicates the version number of the ASP.NET ISAPI that the application uses. The ASP.NET ISAPI version
1. Click Start, and then click Run. In the Open text box, type cmd, and then click OK.
%WindowsDirectory%\Microsoft.NET\Framework\v1.0.3705\
3. Type the following command to configure the ASP.NET 1.0 application in IIS:
aspnet_regiis -s w3svc/1/root/ApplicationName
To remove ASP.NET 1.0 from this application, repeat steps 1and 2, and then type the following command:
aspnet_regiis -k w3svc/1/root/ApplicationName
Configure ASP.NET 1.1 for the Application When ASP.NET 1.0 is configured on the root Web site, follow these
steps to configure ASP.NET 1.1 to run an application:
1. Click Start, and then click Run. In the Open text box, type cmd, and then click OK.
%WindowsDirectory%\Microsoft.NET\Framework\v1.1.4322
3. If ASP.NET 1.1 is not already registered, type the following command to register it: aspnet_regiis -ir Note
The -ir option registers ASP.NET 1.1 without updating the scripts in IIS.
aspnet_regiis -s w3svc/1/root/ApplicationName
To remove ASP.NET 1.1 from this application, repeat steps 1 and 2, and then type the following command:
aspnet_regiis -k w3svc/1/root/ApplicationName
This happens for example, whe you try to export data to excel from a datagrid.
The problem occurs if the server is using Secure Sockets Layer (SSL) and has added one or both of the following
Pragma: no-cache
Cache-control: no-cache,max-age=0,must-revalidate
For more details refer PRB: Internet Explorer Is Unable to Open Office Documents from an SSL Web Site
1.16 Why do I get error message "Unable to start debugging on the web
server. The server does not support debugging of ASP.NET or ATL Server
applications. ..."?
You would get this error if the application mappings for ASP.NET file name extensions (such as .aspx) are not
For more information refer PRB: Cannot Debug ASP.NET Web Application
ASP.NET is a programming framework built on the common language runtime that can be used on a server to build
• What is ASP.NET
• ASP.NET OverView
2.2 Why does my ASP.NET file have multiple <form> tag with runat=server?
.Net framework provides an Administration utility that manages the installation and uninstallation of multiple
C:\WINNT\Microsoft.NET\Framework\v**\aspnet_regiis.exe
VB.NET
Response.Write(System.Environment.Version.ToString() )
C#
Response.Write(System.Environment.Version.ToString() );
Yes you can pass querystring from .asp to ASP.NET page .asp
<%response.redirect "webform1.aspx?id=11"%>
.aspx
VB.NET
C#
<%--<asp:Label id="Label1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 48px"
runat="server">Label</asp:Label>--%>
2.6 What is a ViewState?
In classic ASP, when a form is submitted the form values are cleared. In some cases the form is submitted with huge
information. In such cases if the server comes back with error, one has to re-enter correct information in the form.
But submitting clears up all form values. This happens as the site does not maintain any state (ViewState).
In ASP .NET, when the form is submitted the form reappears in the browser with all form values. This is because
ASP .NET maintains your ViewState. ViewState is a state management technique built in ASP.NET. Its purpose is to
keep the state of controls during subsequent postbacks by the same user. The ViewState indicates the status of the
page when submitted to the server. The status is defined through a hidden field placed on each page with a <form
runat="server"> control.
If you want to NOT maintain the ViewState, include the directive <%@ Page EnableViewState="false"%> at
the top of an .aspx page If you do not want to maintain Viewstate for any control add the attribute
EnableViewState="false" to any control. For more details refer The ASP.NET View State
2.7 Where can I get the details on Migration of existing projects using various
technologies to ASP.NET?
Microsoft has designed Migration Assistants to help us convert existing pages and applications to ASP.NET. It does
not make the conversion process completely automatic, but it will speed up project by automating some of the steps
VB.NET
System.DateTime.Now.ToShortDateString()
System.DateTime.Now.ToShortTimeString()
C#
System.DateTime.Now.ToShortDateString();
System.DateTime.Now.ToShortTimeString();
VB.NET
C#
Call the Request.QueryStringmethod passing in the key. The method will return the parameter value associated
Request.QueryString("id")
C#
Request.QueryString["id"];
2.12 How to Set Focus to Web Form Controls By Using Client-Side Script?
<script language="javascript">
function SetFocus()
{
// W3C approved DOM code that will work in all modern browsers
if (document.getElementById)
document.getElementById('txt2').focus();
else
// To support older versions of IE:
if (document.all)
document.all("txt2").focus();
return false;
}
</script>
For
• VB.NET
• C#
2.15 How to catch the 404 error in my web application and provide more
useful information?
VB.NET
C#
Exception ex = Server.GetLastError().GetBaseException();
if (ex.GetType() == typeof(System.IO.FileNotFoundException))
{
//your code
Response.Redirect ("err404.aspx");
}
else
{
//your code
}
Server.Transfer preserves the current page context, so that in the target page you can extract values and such.
However, it can have side effects; because Server.Transfer doesnt' go through the browser, the browser doesn't
update its history and if the user clicks Back, they go to the page previous to the source page.
Another way to pass values is to use something like a LinkButton. It posts back to the source page, where you can
get the values you need, put them in Session, and then use Response.Redirect to transfer to the target page. (This
does bounce off the browser.) In the target page you can read the Session values as required.
Refer to Passing Values Between Web Forms Pages for more information.
2.17 What are the differences between HTML versus Server Control?
Refer
You can't change it. The action attribute is owned by ASP.NET. Handle Events and Transfer.
For work around refer to Paul Wilson's Multiple Forms and Non-PostBack Forms - Solution
2.19 Is there any control that allows user to select a time from a clock - in
other words is there a clock control?
Peter Blum has developed some controls. Check out Peter's Date Package: TimeOfDayTextBox and DurationTextBox
Controls
VB.NET
C#
VB.NET
ASP.Net does not recognize the standard ASP global.asa file. Instead it uses a file named global.asax with the same
ASP.Net actually has very solid internal garbage collection. So this is not an issue as it was in previous versions of
2.25 Are there resources online with tips on ASP to ASP.Net conversions?
Microsoft has deisnged The ASP to ASP.NET Migration Assistant help us convert ASP pages and applications to
ASP.NET. It does not make the conversion process completely automatic, but it will speed up project by automating
The following Code Migration Assistants are discussed in the link below.
Your ISP must first create an IIS application and apply the Front Page Server Extensions to it. Then in Visual Studio
.NET, select the "Project | Copy Project" menu. Then enter the URL and select the FrontPage web access method.
The "Copy Project" feature copies all of the necessary files to your ISP's machine for your ASP.NET application to
run.
You can also FTP your files to your ISP web server. But you must know which files to upload. For more details refer
PRB: Remote ASP.NET Projects Require IIS on the Client Computer or FrontPage Server Extensions on the Server
Computer
2.27 Why do i get error message "Could not load type" whenever I browse to
my ASP.NET web site?
Your code-behind files for either your .aspx or the global.aspx page have not been complied. Use Visual Studio
.NET's "Build | Build Solution" menu, or run the command line compiler.
For more details refer PRB: "Could not load type" error message when you browse to .aspx page
SqlDataSourceControl lets you connect and work with MS SQL DB, while AccessDataSourceControl do the same
thing but for MS Access DB. Therefore SqlDataSourceControl can't help you in your MySql connectivity .
For Connectivity with MySql refer Accessing MySQL Database with ASP.NET
No.
ASP pages can run in the same site as ASP.NET pages, but you can't mix in a page. Also ASP and ASP.NET won't
Src attribute means you deploy the source code files and everything is compiled JIT (just-in-time) as needed. Many
people prefer this since they don't have to manually worry about compiling and messing with dlls -- it just works. Of
course, the source is now on the server, for anyone with access to the server -- but not just anyone on the web.
CodeBehind attribute doesn't really "do" anything, its just a helper for VS.NET to associate the code file with the
aspx file. This is necessary since VS.NET automates the pre-compiling that is harder by hand, and therefore the Src
attribute is also gone. Now there is only a dll to deploy, no source, so it is certainly better protected, although its
2.31 How can I get the value of input box with type hidden in code-behind?
You can set the runat= server for the hidden control and you can use ControlName.Value to get its value in
CodeBehind file
2.32 I have created a .NET user control page (.ascx) but I cannot compile and
run it.
User control (ascx) can't be run on it own, but you can drag it onto any web page (aspx) and then run it.
The .resx resource file format consists of XML entries, which specify objects and strings inside XML tags. This is
useful for localization. For more details refer Resources in .resx files
Every WebControl derived control has a CssClass property which allows you to set it's format to a style sheet.
2.35 Can I recieve both HTML markup for page and code in the ASP.NET web
page's source code portion in the Web browser?
No source code or web control syntax is passed back to the web browser.
2.36 Why can't I put <%@ Page Language="C " %> where at the top of an
ASPX file and write my server-side scripts in C ?
The parsers ASP.NET uses to extract code from ASPX files understand C#, Visual Basic.NET, and JScript.NET. You can
2.37 ASP pages that worked pefectly on Windows 2000 Server and IIS 5.0 do
not work on Windows 2003 Server with IIS 6.0. ASP.NET pages work fine.
Why?
Start -> Settings -> Control Panel -> Administrative Tools -> and double clicking IIS Manager.
Go to the Web Service Extensions tab, click Active Server Pages, then press the "Allow" button on the left
2.38 Why do I get error message "Error creating assembly manifest: Error
reading key file 'key.snk' -- The system cannot find the file specified"?
Check the location of the key.snk file relative to the assembly file. Provide an explicit path or a relative path.
<Assembly: AssemblyKeyFileAttribute("Drive:\key.snk")>
VB.NET
C#
2.40 What is the best way to output only time and not Date?
Response.Write(DateTime.Now.ToString("hh:mm:ss"))
C#
Response.Write(DateTime.Now.ToString("hh:mm:ss"));
VB.NET
Response.Write ( Request.UrlReferrer.ToString())
C#
Response.Write ( Request.UrlReferrer.ToString());
Use a <script runat=server> block instead of the <% %> syntax to define Subs.
Make sure you have proper events associated with the code and have start and end of procedure or function wirtten
properly.
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.
FormsAuthentication.SignOut()
C#
FormsAuthentication.SignOut();
VB.NET
C#
string sLang ;
sLang = Request.UserLanguages[0];
Response.Write (sLang);
• CurrentCulture property : affects how the .NET Framework handles dates, currencies, sorting and
formatting issues
• CurrentUICulture property : determines which satellite assembly is used when loading resources
2.49 Can I read the hard disk serial # of the client computer using ASP.NET?
No. Such information is not passed to the server with a http request.
e is an event argument object that contains more information about the event
An event handler is used when one object wants to be notified when an event happens in another object
• Contain all information necessary for the browser(or other client program) to locate the resource named in
the URL
o This includes protocol moniker used( i.e http://, ftp://..etc..), Server's Domain name or IP address
Relative URLs:
• Only provide information necessary to locate a resource relative to the current document(document
A URL is the address of some resource on the Web, which means that normally you type the address into a browser
and you get something back. There are other type of resources than Web pages, but that's the easiest conceptually.
The browser goes out somewhere on the Internet and accesses something.
A URI is just a unique string that uniquely identifies something, commonly a namespace. Sometimes they look like a
URL that you could type into the address bar of your Web browser, but it doesn't have to point to any physical
resource on the Web. It is just a unique set of characters, that, in fact, don't even have to be unique.
URI is the more generic term, and a URL is a particular type of URI in that a URL has to uniquely identify some
VB.NET
C#
TimeSpan ts = TimeSpan.FromMilliseconds(10000);
Response.Write (ts.ToString () );
or
However, note that each source file will be compiled individually into its own assembly, so they cannot have
VB.NET
2.56 How can I ensure that application-level variables are not updated by
more than one user simultaneously?
You can't use MsgBox or MessageBox.Show in ASP.NET WebForm. You maybe use:
VB.NET
Response.Write("<script>alert('Hello');</script>")
C#
Response.Write("<script>alert('Hello');</script>") ;
VB.NET
bool blnValid=false;
try
{
DateTime.Parse(MyString);
blnValid=true;
}
catch
{
blnValid=false;
}
Namespaces and Class names are case Sensitive. Namespaces imported using the @ Import Directive will cause an
VB.NET
C#
VB.NET
Dim dt As DateTime = DateTime.ParseExact("0299", New String() {"My", "M/y"}, Nothing,
System.Globalization.DateTimeStyles.None)
C#
2.63 When the User is prompted a File Download dialogbox, if the user selects
"Save" then the "Save as" dialog box is displayed. Is there any way for me to
retrieve the filename and directory path specified by the user on the File
Download dialog box?
Clients do not report information back about where the user selects to save the content, so there isn't an easy way
to do this. Instead, you would need to ask the user before using the content-disposition for a file path, and then you
could specify the filename parameter for the content-disposition header. Still, the user is free to change that path
VB.NET
C#
TextBox1.Visible =!TextBox1.Visible ;
2.65 How to check if the user is using a secure or non secure connection?
The Request Object defines a Property called IsSecureConnection, that will indicate whether http:// or https:// has
been used.
Response.Redirect
• Tranfers the page control to the other page, in other words it sends the request to the other page.
• Causes the client to navigate to the page you are redirecting to. In http terms it sends a 302 response to
Server.Transfer
• Only transfers the execution to another page and during this you will see the URL of the old page since only
• HttpContext.Current.Server.MachineName
• HttpContext.Current.Request.ServerVariables["LOCAL_ADDR"]
The first one should return the name of the machine, the second returns the local ip address.
Note that name of the machine could be different than host, since your site could be using host headers
The value of validateRequest is set to 'true' by default, which means that the framework will automatically deny
2.70 What is the different between <%# %> and <%= %>?
The <%# %> is used for databinding where as <%= %> is used to output the result of an expression. The
expression inside <%# %> will be executed only when you call the page's or control's DataBind method. The
expression inside <%= %> will be executed and displayed as and when it appears in the page.
2.71 What permissions do ASP.NET applications posses by default?
By default ASP.NET Web applications run as ASP.NET user. This user has limited permissions equivalent to the User
Group.
default.aspx
Admin/login.aspx
Misc/testpage.aspx
And you are on the login.aspx and want your user to navigate to the default.aspx (or testpage.aspx) file. Then you
can use
• Response.Redirect ("../default.aspx")
• Response.Redirect ("../Misc/testpage.aspx")
2.73 How can I specify the "upload a file" input textbox in a form to be read
only so that the user can click on the browse button and pick a file but they
cannot type anything into the textbox next to the browse button.
VB.NET
'Declare
Protected WithEvents Title1 As System.Web.UI.HtmlControls.HtmlGenericControl
'In Page_Load
Title1.InnerText ="Page 1"
C#
//Declare
protected System.Web.UI.HtmlControls.HtmlGenericControl Title1 ;
//In Page_Load
Title1.InnerText ="Page 1" ;
2.75 Why do I get the error message "Object must implement IConvertible".
How can I resolve it?
The common cause for this error is specifying a control as a SqlParameter's Value instead of the control's text value.
For example, if you write code as below you'll get the above error:
VB.NET
C#
To resolve it, specify the control's Text property instead of the control itself.
VB.NET
nameParameter.Value = txtName.Text
C#
nameParameter.Value =txtName.Text;
IIS configuration. If you have multiple websites inside IIS, make sure the configuration is applied on the right
website (or on all websites by applying the configuration on the server-level using the properties dialog, configure
WWW service).
2.79 How to automatically get the latest version of all the asp.net solution
items from Source Safe when opening the solution?
In VS.NET you can go to Tools > Options > Source Control > General and check the checkbox for Get everything
This retrieves the latest version of all solution items when you open the solution.
2.80 How to convert the datetime into a string for use in the SQL ' statement?
VB.NET
C#
2.81 How to make VS.Net use FlowLayout as the default layout rather than
the GridLayout?
2003\VC#\VC#Wizards\CSharpWebAppWiz\Templates\1033
to
Note:Before changing any templates it's a good idea to make backup copies of them
Or rather than above approach you can change the behavior for new files on a per project basis in Visual Studio by:
1. Right clicking on the project name (Ex: "WebApplication1)" in Solution Explorer, and select "Properties".
2. From project properties window, under Common Properties>Designer Defaults>Page Layout change "Grid"
to "Flow".
No. DataReader provides a means of reading a forward-only stream of rows from a database.
• Server.Transfer is used to End the current weform and begin executing a new webform. This method works
• Server.Execute is used to begin executing a new webform while still displaying the current web form. The
contents of both forms are combined. This method works only when navigating to a webform page(.aspx)
VB.NET
End Sub
C#
SqlConnection myconnection ;
SqlCommand mycmd ;
string strSql ;
SqlDataReader myReader ;
private void btnLogin_Click(object sender, System.EventArgs e)
{
myconnection = new SqlConnection("Server=localhost;uid=sa;password=;database=northwind;");
strSql = "Select * from usertbl where username=" + "'" + txtUserName.Text + "'" + " and userpassword=" + "'"
+ txtPassword.Text + "'";
mycmd = new SqlCommand(strSql, myconnection);
myconnection.Open();
myReader = mycmd.ExecuteReader(CommandBehavior.CloseConnection);
if (myReader.Read() )
{
Response.Write("Welcome");
}
else
{
Response.Write("Access Denied");
}
}
VB.NET
C#
No. ASP.NET uses parsers to strip the code from ASPX files and copy it to temporary files containing derived Page
Yes. Place the DLL containing the type in the application root's bin directory and ASP.NET will automatically load the
DLL when the type is referenced. This is also what happens when you add a custom control from the toolbox to your
web form.
2.88 How can I have a particular Web page in an ASP.NET application which
displays its own error page.
This can be done by setting the ErroPage attribute of Page Directive or ErrorPage property of Page Class to the
In web.config
• You add the class later on and run the project without compiling
• You have the class but you do not specify the namespace via Imports or using keyword
3.28 Why do I get the error message "Compiler Error Message: CS1595"?
This problem occurs because the C# compiler does not have permission to access the folders in the path to the
mscorlib.dll assembly
To resolve this problem, modify the compiler definition for the C# compiler to include the /nostdlib option. The
/nostdlib option prevents the import of the mscorlib.dll assembly, which defines the entire System namespace. To
include the /nostdlib option in the C# compiler definition on a computer, follow these steps:
2. In the definition for C#, add the compilerOptions attribute with a value of /nostdlib. For example:
<compiler language="c#;cs;csharp"
extension=".cs"
type="Microsoft.CSharp.CSharpCodeProvider, System,
Version=1.0.3300.0,
Culture=neutral,
PublicKeyToken=b77a5c561934e089"
warningLevel="1"
compilerOptions="/nostdlib" />
For more details refer PRB: "Compiler Error Message: CS1595" Error Message When You Use the C# Compiler to
3.29 I get error message at runtime "Value null was found where an instance
of an object was required" when using Application state variables. why?
Application State variables must be initialized in C# before any operation is performed on them. For example.:
You need to assign value to Counter state variable before performing the case (int)Session["Counter"].
3.30 I installed Windows 2003 Standard Edition, then VS.NET and SQL Server
2K with SP3. When I build web project connecting to the database in VS.NET,
the compliler gives me the following error:Login failed for user 'NT
AUTHORITY\NETWORK SERVICE',why?
Add NT AUTHORITY\NETWORK SERVICE account to SQL Server , which will be in the local group. Make sure to give
VB.NET