1How
do I use the aspnet_compiler.exe to precompile the ASP.NET website?[Top]
Prerequisites:.Net Framework 2.0 or its later version and IIS must be inserted on the computer. In addition, please ensure that the demo assumes
there is an ASP.NET website on “d:\WebSiteDemo” and Virtual Directory named “PrecompileWebSite” in IIS.
Here is the method to use aspnet_compiler.exe to precompile the ASP.NET application:
·Precompile the ASP.NET website and output the compiled application in Virtual Directory of local IIS
Note: The aspnet_compiler.exe is under the
%windir%\Microsoft.NET\Framework\v2.0.50727\ folder. The –v
option specifies the virtual path of the application to be compiled, and
– p option specifies the full network path or local disk path of the root directory that contains the application to be compiled. “d:\PreCompileResult” is the network path or local disk path to the root directory that will contain the compiled application.
For more information about aspnet_compiler.exe, please visit the following website:
2What
is the best way to deploy ASP.NET web application?[Top]
After the ASP.NET web application is finish, we will deploy it on production server. Here is the best way to deploy it:
·Use XCOPY to deploy the ASP.NET application
Run the XCOPY command line from CMD.exe to copy the application file to the production web server directory:
xcopy <source path> <destination path>
Note: In this command, <source path> is the full path of your web application, and <destination path> is the full path of the directory
where the application will be deployed.
Note In this command, <source path> is the full path of your Web application, <destination path> is the full path of the directory where
the application will be deployed, and <virtual path> is the virtual path of the application.
Please refer to FAQ: How do I use aspnet_compiler.exe to precompile ASP.NET website in this document. This is an example of this method.
·Use Web Setup installer to deploy ASP.NET application
To deploy a Web application to target server, please create a Web Setup project, add ASP.NET web application as its input, and then build it, copy it to the target server, and run this installer to install
the application using the wizard.
3What
is the difference between the updatable and without non-updatable option while precompiling ASP.NET website?[Top]
When precompiling the ASP.NET website, there is an option “Allow this precompiled site to be updatable” in Publish Utility using Visual Web Developer or the
–u option while using aspnet_compiler command line. If we enable “Allow this precompiled site to be updatable” option, it doesn’t mean that we can change everything on the precompiled website. Let’s see what the difference
is while the“Allow this precompiled site to be updatable”
option is enabled or not:
·Precompiling without the updatable option checked:
If this option is disabled, the compiler will not only compile source code into assembly, but also produces assemblies from markup of page, resource files, etc. In the output, compiler removes all the source
code and markup from page which will leave a placeholder with empty content. To change the website except for its configuration, we need to recompile the website and redeploy the layout.
·Precompiling with updatable option checked:
With this option enabled, the compiler will not remove the markup of page and so we can make limited changes, such as change the arrangement of controls, colors, fonts, and other appearance aspects of pages.
Additionally, when the page is requested, ASP.NET will perform further compilation in order to create output from the markup.
For more information about the updatable option, please visit the following website:
4What
is the difference of ASP.NET application identity security context when it is running on IIS and ASP.NET Development Server?[Top]
In some cases, ASP.NET web application can create, delete file when it is running on ASP.NET Development Server, but we encounter the permission-related issue such as Access to the path ‘**’ is denied on IIS; or we recieve
“Login failed for user **”on IIS whenASP.NET web application uses Trusted_Connection enabled connection string with integrated authentication mode, etc. The cause is that ASP.NET application identity security
context is different when it is running on IIS and ASP.NET Development Server.
Here is the difference:
·In the IIS case:
By default, when ASP.NET application is running on IIS,ASP.NET worker process runs using an account (“ASPNET” for IIS 5.1 and “NETWORK SERVICE” for IIS 6/7) with weaker privileges than the Local System account. You can configure ASP.NET application process identity by referring to the following steps:
1.IIS 5
Configure the process identity in machine configuration file
Note: We can also use Impersonation to impersonate a specific user which has more privileges. For more information about Impersonation, please visit the following website:http://msdn.microsoft.com/en-us/library/ms998351.aspx
·In the VS development server case:
The Identity on ASP.NET Development Server: when ASP.NET application is running on ASP.NET Development Server, its worker process runs using account that you login the system and it has more privileges.
Note: If you are using VISTA or WIN 7, there is UAC (User Account Control) which is used to improve the security of Microsoft Windows by limiting application software to standard user
privileges until an administrator authorizes an increase in privilege level (Run as Administrator).
5How
do I use the aspnet_merge.exe command line to merge precompiled assemblies?[Top]
For the ASP.NET website, compiler will generate many assemblies for it. To compile all assemblies into the ASP.NET web application project, use the aspnet_ merge.exe command line.
Prerequisites:.Net Framework 2.0 or its later version and IIS must be inserted on the computer. In additional,please ensure the demo assumes
there is a precompiled ASP.NET website on “d:\PrecompiledWebSiteDemo”, and this website contains sub-folder which contains
.aspx page.
Here is how use the aspnet_merge.exe command line to merge precompiled assemblies:
The ASP.NET website project doesn’t have post-build and pre-build Events existed in ASP.NET web application, but we can add Web Deployment project for ASP.NET website to do post-build and pre-build Events.
To do this, follow the steps below:
1.Open ASP.NET website “WebSiteDemo” from Visual Studio 2008
2.Right click website from Solution Window
and then select Add Web Deployment Project
3.Type the Name for example “WebSite_Deploy” and browse the Location you want and then click OK
4.Right click “WebSite_Deploy” project from Solution Window and then select
Open Project File
5.Uncomment Targets named “BeforeBuild” and “AfterBuild” which equal to post-build
and pre-build Events:
7How
do I deploy ASP.NET application with SQL Express Database on the remote server?[Top]
Considering that you want to deploy ASP.NET application with database on the remote shared host server.How to make it easy to deploy SQL Express Database on the remote server?
8How
do I modify web.config in Web Setup project using Custom Action?[Top]
Web Setup project provides an advantage over copying files to server. With web setup project, the installer automatically handles the issue with registration and configuration. However, sometimes, we want to know how to configure
ASP.NET Web Application, such as ASP.NET version, web.config modification while installing the ASP.NET application with installer on server.
The answer is the Custom Action of Web Setup which provides the utility to configure ASP.NET Web Application, such as ASP.NET version, web.config modification while installing the ASP.NET application with installer on server.
This FAQ demonstrates how to use Custom Action to modify web.config’s appSettings section during installation on server:
·Create ASP.NET Web Application
1.Start Visual Studio 2008 and create an ASP.NET Web Application using
File -> New -> Project -> Select
ASP.NET Web Application from Visual C# Project types -> OK. In this case, we name it WebApplicationDemo.
2.Add the following appSettings section to web.config file. It is for saving data that the customer inputs while installing the ASP.NET application with installer on server:
<appSettings>
<add key="UserData" value="The Value"/>
</appSettings>
3.Add the following code in PageLoad event of Default.aspx.cs file:
Response.Write("AppSettings Section with the value of key \"UserData\" is " + strResult);
·Create Web Setup Project
1.Right click solution from Solution Window and select
Add -> New Project -> Select Web Setup Project from Setup and Deployment under Other Project Types -> OK. In this case, we name it WebSetupDemo.
2.Right click WebSetupDemo from Solution Window and then select
Add -> Project Output -> select WebApplicationDemo from Project dropdown list -> select
Primary output and Content Files -> OK.
·Create Custom Action Class Library
1.Right click solution from Solution Window and select
Add -> New Project -> Class Library from Visual C# Project types -> OK. We name it CustomActionDemo.
2.Delete default Class1.cs and right click CustomActionDemo from Solution Window and then select
Add -> New Item -> select Installer Class -> OK. In this case, we name it CustomActionDemo.
3.Add the following code to CustomActionDemo.Designer.cs
/// <summary>
///Override bass install class's Install method
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
// Get the web application's virtual directory on target server
1.Right click WebSetupDemo from Solution Window and then select
Add -> Project Output -> select CustomActionDemo from Project dropdown list -> select
Primary output -> OK.
2.Right click WebSetupDemo from Solution Window and then select
View -> Custom Actions, and then right click Install folder -> select
Add Custom Action -> select Primary output from CustomActionDemo under Web Application Folder -> OK.
3.Right click Primary output from CustomActionDemo and select Properties Window to enter its Properties Window, and then input the following content in the CustomActionData attribute:
4.Right click WebSetupDemo from Solution Window and then select
View -> UserInterface, Right click
Start under Install -> select Add Dialog -> select Textboxs (A) -> OK. Right click Textboxs (A) -> click Move Up to list it before Confirm Installation interface.
5.Right click Textboxs (A) to enter its Properties Window, and change
BannerText to “Modify AppSetting Section”, BodyText to “Input the value for AppSetting Section”, Edit1Label to “Value:” and type STRNEWVALUE in the Edit1Property attribute. After that, set Edit2Visible, Edit2Visible, Edit2Visible
to false.
Now, right click WebSetupDemo from Solution and select Build. After successfully building it, right click WebSetupDemo and select Install to install it. In the third wizard box of installation, there is a Textbox for inputting.
After the installation is finish, browse the Default.aspx of installed web application on IIS and you will see the value you input in the wizard on default.aspx page.
9Why
do I receive the error "Using section registered as allowDefinition='MachineToApplication'…. " when ASP.NET web application is deployed on IIS?[Top]
Consider the following scenario: ASP.NET web application is running fine from Visual Studio, but we receive the error “Using section registered as allowDefinition='MachineToApplication’” when it is deployed
on IIS. What does the error mean and how to resolve it?
Here is the answer:
The error message means that the section with the
allowDefinition attribute to MachineToApplication only can be in the machine.config, root web.config and application root level web.config.
When you receiving the error, please check the following lists:
·ASP.NET application only has one web.config
Please make sure your website is configured as
Application on IIS.
·ASP.NET application contains multiple web.config
Check if the web.config file existed in sub-directory contains the section with the
allowDefinition attribute to MachineToApplication, such as
Authentication section. We can either configure sub-directory as Application or remove the section from sub-web.config.
10Why
do I receive the "System.Security.SecurityException:..." error on IIS?[Top]
Consider the following scenario: ASP.NET web application is running fine from Visual Studio, but we receive the error “System.Security.SecurityException:..” such as the post on
http://forums.asp.net/t/1406374.aspxwhen it is deployed on IIS. What does the error mean and how to resolve it?
Here is the answer:
There is Code Access Security (CAS) feature in ASP.NET application, which restricts the types of resources the ASP.NET application can access and the types of operations it can perform. It includes the predefined trust levels:
Full|High|Medium|Low|Minimal.
While the ASP.NET application is developing on Visual Studio, the code access security is Full trust level by default and application can implement more works. However, most servers are configured to Medium level to restrict
ASP.NET application.
To resolve the error, configure the ”trust level” option of the ASP.NET application to Full in the web.config:
<system.web>
...
<trust level="Full" />
...
</system.web>
Note: If the administrator uses
allowOverride with true value to protect ” trust level” otpion on machine level web.config, we cannot modify it in application level web.config.
11How
do I configure IIS to allow URL with wildcard extension for ASP.NET application on IIS?[Top]
Here is the answer:
·In the IIS 6 case:
1.Open IIS 6 Management and enter website’s
Properties page
2.Click Configuration on the
Home Directory tab
3.Click Insert to open
Add/Edit Application Extension Mapping
4.Browse aspnet_isapi.dll (By default, it is in
\%windows%\microsoft.net\framework\v2.0.50727\ folder.) in the
Executable textbox and uncheck Verify File Exists
5.Click OK
·In the IIS 7 Classic mode case:
1.Open IIS 7 Management
2.Choose Handler Mapping in IIS section
3.Click Add Wildcard Script Map to open
Add Wildcard Script Mapping
4.Browse aspnet_isapi.dll (By default, it is in
\%windows%\microsoft.net\framework\v2.0.50727\ folder.) in the
Executable textbox and type the name you want
5.Click Yes
Note: There is no need to configure wildcard for IIS 7 Integrated mode.
Vince Xu - M...
All-Star
80367 Points
6801 Posts
FAQ in ASP.NET Setup & Deployment
Apr 08, 2010 02:19 AM|LINK
1 How do I use the aspnet_compiler.exe to precompile the ASP.NET website?
2 What is the best way to deploy ASP.NET web application?
3 What is the difference between the updatable and without non-updatable option while precompiling ASP.NET website?
4 What is the difference of ASP.NET application identity security context when it is running on IIS and ASP.NET Development Server?
5 How do I use the aspnet_merge.exe command line to merge precompiled assemblies?
6 How do I use Web Deployment project's post-build and pre-build Events?
7 How do I deploy ASP.NET application with SQL Express Database on the remote server?
8 How do I modify web.config in Web Setup project using Custom Action?
9 Why do I receive the error "Using section registered as allowDefinition='MachineToApplication'…. " when ASP.NET web application is deployed on IIS?
10 Why do I receive the "System.Security.SecurityException:..." error on IIS?
11 How do I configure IIS to allow URL with wildcard extension for ASP.NET application on IIS?
1 How do I use the aspnet_compiler.exe to precompile the ASP.NET website?[Top]
Prerequisites:.Net Framework 2.0 or its later version and IIS must be inserted on the computer. In addition, please ensure that the demo assumes there is an ASP.NET website on “d:\WebSiteDemo” and Virtual Directory named “PrecompileWebSite” in IIS.
Here is the method to use aspnet_compiler.exe to precompile the ASP.NET application:
· Precompile the ASP.NET website and output the compiled application in Virtual Directory of local IIS
aspnet_compiler.exe -v PrecompileWebSite -p d:\WebSiteDemo
· Precompile the ASP.NET website and output the compiled application to the network path or local disk path
aspnet_compiler.exe -v PrecompileWebSite -p d:\WebSiteDemo d:\PreCompileResult
Note: The aspnet_compiler.exe is under the %windir%\Microsoft.NET\Framework\v2.0.50727\ folder. The –v option specifies the virtual path of the application to be compiled, and – p option specifies the full network path or local disk path of the root directory that contains the application to be compiled. “d:\PreCompileResult” is the network path or local disk path to the root directory that will contain the compiled application.
For more information about aspnet_compiler.exe, please visit the following website:
http://msdn.microsoft.com/en-us/library/ms229863(VS.80).aspx
2 What is the best way to deploy ASP.NET web application?[Top]
After the ASP.NET web application is finish, we will deploy it on production server. Here is the best way to deploy it:
· Use XCOPY to deploy the ASP.NET application
Run the XCOPY command line from CMD.exe to copy the application file to the production web server directory:
xcopy <source path> <destination path>
Note: In this command, <source path> is the full path of your web application, and <destination path> is the full path of the directory where the application will be deployed.
For more information about XCOPY, please visit the following website: http://msdn.microsoft.com/en-us/library/f735abw9.aspx
· Use Visual Web Developer Publish utility to deploy ASP.NET application
Prerequisites: this method assumes that you are using a designer, such as Visual Web Developer or Visual Studio.
Follow these steps to deploy ASP.NET web application:
1. Click Publish Web Site on the Build menu of Visual Web Developer
2. Click the ellipsis button (…) to browse to the location where you want to publish the Web site.
3. Click OK.
Note The Publish utility is not available in Visual Web Developer Express Edition.
For more information about Publish utility, please visit the following Web site: http://msdn.microsoft.com/en-us/library/20yh9f1b(VS.80).aspx
· Use the aspnet_compiler.exe command line to deploy ASP.NET application
Use the aspnet_compiler.exe command line to precompile ASP.NET website application for deployment:
aspnet_compiler.exe -v <virtual path> -p <source path> <destination path>
Note In this command, <source path> is the full path of your Web application, <destination path> is the full path of the directory where the application will be deployed, and <virtual path> is the virtual path of the application.
Please refer to FAQ: How do I use aspnet_compiler.exe to precompile ASP.NET website in this document. This is an example of this method.
· Use Web Setup installer to deploy ASP.NET application
To deploy a Web application to target server, please create a Web Setup project, add ASP.NET web application as its input, and then build it, copy it to the target server, and run this installer to install the application using the wizard.
For more information about Publish utility, please visit the following website: http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx
3 What is the difference between the updatable and without non-updatable option while precompiling ASP.NET website?[Top]
When precompiling the ASP.NET website, there is an option “Allow this precompiled site to be updatable” in Publish Utility using Visual Web Developer or the –u option while using aspnet_compiler command line. If we enable “Allow this precompiled site to be updatable” option, it doesn’t mean that we can change everything on the precompiled website. Let’s see what the difference is while the “Allow this precompiled site to be updatable” option is enabled or not:
· Precompiling without the updatable option checked:
If this option is disabled, the compiler will not only compile source code into assembly, but also produces assemblies from markup of page, resource files, etc. In the output, compiler removes all the source code and markup from page which will leave a placeholder with empty content. To change the website except for its configuration, we need to recompile the website and redeploy the layout.
· Precompiling with updatable option checked:
With this option enabled, the compiler will not remove the markup of page and so we can make limited changes, such as change the arrangement of controls, colors, fonts, and other appearance aspects of pages. Additionally, when the page is requested, ASP.NET will perform further compilation in order to create output from the markup.
For more information about the updatable option, please visit the following website:
http://msdn.microsoft.com/en-us/library/399f057w(VS.80).aspx
4 What is the difference of ASP.NET application identity security context when it is running on IIS and ASP.NET Development Server?[Top]
In some cases, ASP.NET web application can create, delete file when it is running on ASP.NET Development Server, but we encounter the permission-related issue such as Access to the path ‘**’ is denied on IIS; or we recieve “Login failed for user **” on IIS whenASP.NET web application uses Trusted_Connection enabled connection string with integrated authentication mode, etc. The cause is that ASP.NET application identity security context is different when it is running on IIS and ASP.NET Development Server.
Here is the difference:
· In the IIS case:
By default, when ASP.NET application is running on IIS, ASP.NET worker process runs using an account (“ASPNET” for IIS 5.1 and “NETWORK SERVICE” for IIS 6/7) with weaker privileges than the Local System account. You can configure ASP.NET application process identity by referring to the following steps:
1. IIS 5
Configure the process identity in machine configuration file
<processModel enable="true" userName="account" password="pwd"/>
For more information about process identity, please visit the following website: http://msdn.microsoft.com/en-us/library/dwc1xthy.aspx
2. IIS 6
Change the Application pool to use another user on IIS 6. For more information about configuring Application Pool Identity with IIS 6.0, please visit the following website: http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/f05a7c2b-36b0-4b6e-ac7c-662700081f25.mspx?mfr=true
3. IIS 7
Change the Application pool to use another user on IIS 7. For more information about specifying an Identity for an Application Pool on IIS 7, please visit the following website: http://technet.microsoft.com/en-us/library/cc771170(WS.10).aspx
Note: We can also use Impersonation to impersonate a specific user which has more privileges. For more information about Impersonation, please visit the following website: http://msdn.microsoft.com/en-us/library/ms998351.aspx
· In the VS development server case:
The Identity on ASP.NET Development Server: when ASP.NET application is running on ASP.NET Development Server, its worker process runs using account that you login the system and it has more privileges.
Note: If you are using VISTA or WIN 7, there is UAC (User Account Control) which is used to improve the security of Microsoft Windows by limiting application software to standard user privileges until an administrator authorizes an increase in privilege level (Run as Administrator).
5 How do I use the aspnet_merge.exe command line to merge precompiled assemblies?[Top]
For the ASP.NET website, compiler will generate many assemblies for it. To compile all assemblies into the ASP.NET web application project, use the aspnet_ merge.exe command line.
Prerequisites:.Net Framework 2.0 or its later version and IIS must be inserted on the computer. In additional,please ensure the demo assumes there is a precompiled ASP.NET website on “d:\PrecompiledWebSiteDemo”, and this website contains sub-folder which contains .aspx page.
Here is how use the aspnet_merge.exe command line to merge precompiled assemblies:
aspnet_merge.exe d:\PrecompiledWebSiteDemo -w YourAssemblyName.dll
Note “d:\ PrecompiledWebSiteDemo” contains the precompiled ASP.NET website.
For more information about aspnet_merge.exe, please visit the following website:
http://msdn.microsoft.com/en-us/library/bb397866.aspx
6 How do I use Web Deployment project's post-build and pre-build Events?[Top]
Prerequisites: Web Deployment Project 2008 for Visual Studio 2008 needs to be installed. You can download it from
http://www.microsoft.com/downloads/details.aspx?FamilyId=0AA30AE8-C73B-4BDD-BB1B-FE697256C459&displaylang=en . The demo assumes there is an ASP.NET website on “d:\WebSiteDemo”.
The ASP.NET website project doesn’t have post-build and pre-build Events existed in ASP.NET web application, but we can add Web Deployment project for ASP.NET website to do post-build and pre-build Events.
To do this, follow the steps below:
1. Open ASP.NET website “WebSiteDemo” from Visual Studio 2008
2. Right click website from Solution Window and then select Add Web Deployment Project
3. Type the Name for example “WebSite_Deploy” and browse the Location you want and then click OK
4. Right click “WebSite_Deploy” project from Solution Window and then select Open Project File
5. Uncomment Targets named “BeforeBuild” and “AfterBuild” which equal to post-build and pre-build Events:
<Target Name="BeforeBuild">
<Copy SourceFiles="c:\test.txt" DestinationFiles="d:\test.txt"></Copy>
</Target>
<Target Name="AfterBuild">
<MakeDir Directories="$(OutputPath)\AfterBuild">
</MakeDir>
</Target>
Note: In pre-build event, we copy file and create folder under output directory in post-build event.
For more information about Web Deployment project, please visit the following website:
http://weblogs.asp.net/scottgu/archive/2005/11/06/429723.aspx
7 How do I deploy ASP.NET application with SQL Express Database on the remote server?[Top]
Considering that you want to deploy ASP.NET application with database on the remote shared host server. How to make it easy to deploy SQL Express Database on the remote server?
Prerequisites: SQL Server Hosting Toolkit can be downloaded from http://www.codeplex.com/sqlhost.
The answer is to use SQL Server Hosting Toolkit which can create .sql scripts for the database and execute it on remote host server:
1. Open ASP.NET website using Visual Studio
2. Expend the database you use in Server Explorer
3. Right click the database and select Publish to provider from context items
4. Use Database Publishing Wizard to generate .sql file
5. FTP .sql file to remote host server and execute it to create database
Note: Please don't forget to modify connection to point to new database in connection string of your ASP.NET website on server.
For more information about deploying SQL Server Express database to remote host server, please visit the following website: http://weblogs.asp.net/scottgu/archive/2006/12/22/recipe-deploying-a-sql-database-to-a-remote-hosting-environment-part-1.aspx
8 How do I modify web.config in Web Setup project using Custom Action?[Top]
Web Setup project provides an advantage over copying files to server. With web setup project, the installer automatically handles the issue with registration and configuration. However, sometimes, we want to know how to configure ASP.NET Web Application, such as ASP.NET version, web.config modification while installing the ASP.NET application with installer on server.
The answer is the Custom Action of Web Setup which provides the utility to configure ASP.NET Web Application, such as ASP.NET version, web.config modification while installing the ASP.NET application with installer on server.
This FAQ demonstrates how to use Custom Action to modify web.config’s appSettings section during installation on server:
· Create ASP.NET Web Application
1. Start Visual Studio 2008 and create an ASP.NET Web Application using File -> New -> Project -> Select ASP.NET Web Application from Visual C# Project types -> OK. In this case, we name it WebApplicationDemo.
2. Add the following appSettings section to web.config file. It is for saving data that the customer inputs while installing the ASP.NET application with installer on server:
<appSettings>
<add key="UserData" value="The Value"/>
</appSettings>
3. Add the following code in PageLoad event of Default.aspx.cs file:
// Get the web.config of current application
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");
AppSettingsSection setting = config.AppSettings;
// Retrieve the value from AppSettings Section with key "UserData"
string strResult = setting.Settings["UserData"].Value;
Response.Write("AppSettings Section with the value of key \"UserData\" is " + strResult);
· Create Web Setup Project
1. Right click solution from Solution Window and select Add -> New Project -> Select Web Setup Project from Setup and Deployment under Other Project Types -> OK. In this case, we name it WebSetupDemo.
2. Right click WebSetupDemo from Solution Window and then select Add -> Project Output -> select WebApplicationDemo from Project dropdown list -> select Primary output and Content Files -> OK.
· Create Custom Action Class Library
1. Right click solution from Solution Window and select Add -> New Project -> Class Library from Visual C# Project types -> OK. We name it CustomActionDemo.
2. Delete default Class1.cs and right click CustomActionDemo from Solution Window and then select Add -> New Item -> select Installer Class -> OK. In this case, we name it CustomActionDemo.
3. Add the following code to CustomActionDemo.Designer.cs
/// <summary>
/// Override bass install class's Install method
/// </summary>
/// <param name="stateSaver"></param>
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
// Get the web application's virtual directory on target server
string targetVDir = Context.Parameters["targetvdir"];
// Get the value that customer inputs in Wizard while installing
string strNewValue = Context.Parameters["strnewvalue"];
// Get web.config
Configuration config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/" + targetVDir);
// Retrieve AppSettings Section
AppSettingsSection setting = config.AppSettings;
// Set Settings with key "UserData"
setting.Settings["UserData"].Value = strNewValue;
// Save web.config
config.Save();
}
· Configure Web Setup Works with Custom Action
1. Right click WebSetupDemo from Solution Window and then select Add -> Project Output -> select CustomActionDemo from Project dropdown list -> select Primary output -> OK.
2. Right click WebSetupDemo from Solution Window and then select View -> Custom Actions, and then right click Install folder -> select Add Custom Action -> select Primary output from CustomActionDemo under Web Application Folder -> OK.
3. Right click Primary output from CustomActionDemo and select Properties Window to enter its Properties Window, and then input the following content in the CustomActionData attribute:
/targetvdir="[TARGETVDIR]" /strnewvalue="[STRNEWVALUE]"
4. Right click WebSetupDemo from Solution Window and then select View -> User Interface, Right click Start under Install -> select Add Dialog -> select Textboxs (A) -> OK. Right click Textboxs (A) -> click Move Up to list it before Confirm Installation interface.
5. Right click Textboxs (A) to enter its Properties Window, and change BannerText to “Modify AppSetting Section”, BodyText to “Input the value for AppSetting Section”, Edit1Label to “Value:” and type STRNEWVALUE in the Edit1Property attribute. After that, set Edit2Visible, Edit2Visible, Edit2Visible to false.
Now, right click WebSetupDemo from Solution and select Build. After successfully building it, right click WebSetupDemo and select Install to install it. In the third wizard box of installation, there is a Textbox for inputting. After the installation is finish, browse the Default.aspx of installed web application on IIS and you will see the value you input in the wizard on default.aspx page.
For more information about using Custom Action, please visit the following website: http://weblogs.asp.net/scottgu/archive/2007/06/15/tip-trick-creating-packaged-asp-net-setup-programs-with-vs-2005.aspx
9 Why do I receive the error "Using section registered as allowDefinition='MachineToApplication'…. " when ASP.NET web application is deployed on IIS?[Top]
Consider the following scenario: ASP.NET web application is running fine from Visual Studio, but we receive the error “Using section registered as allowDefinition='MachineToApplication’” when it is deployed on IIS. What does the error mean and how to resolve it?
Here is the answer:
The error message means that the section with the allowDefinition attribute to MachineToApplication only can be in the machine.config, root web.config and application root level web.config.
When you receiving the error, please check the following lists:
· ASP.NET application only has one web.config
Please make sure your website is configured as Application on IIS.
· ASP.NET application contains multiple web.config
Check if the web.config file existed in sub-directory contains the section with the allowDefinition attribute to MachineToApplication, such as Authentication section. We can either configure sub-directory as Application or remove the section from sub-web.config.
For more information about AllowDefinition Property, please visit the following website: http://msdn.microsoft.com/en-us/library/ms228245.aspx
10 Why do I receive the "System.Security.SecurityException:..." error on IIS?[Top]
Consider the following scenario: ASP.NET web application is running fine from Visual Studio, but we receive the error “System.Security.SecurityException:..” such as the post on http://forums.asp.net/t/1406374.aspx when it is deployed on IIS. What does the error mean and how to resolve it?
Here is the answer:
There is Code Access Security (CAS) feature in ASP.NET application, which restricts the types of resources the ASP.NET application can access and the types of operations it can perform. It includes the predefined trust levels: Full|High|Medium|Low|Minimal.
While the ASP.NET application is developing on Visual Studio, the code access security is Full trust level by default and application can implement more works. However, most servers are configured to Medium level to restrict ASP.NET application.
To resolve the error, configure the ”trust level” option of the ASP.NET application to Full in the web.config:
<system.web>
...
<trust level="Full" />
...
</system.web>
Note: If the administrator uses allowOverride with true value to protect ” trust level” otpion on machine level web.config, we cannot modify it in application level web.config.
For more information about Code Access Security, please visit the following website: http://msdn.microsoft.com/en-us/library/ms998326.aspx
11 How do I configure IIS to allow URL with wildcard extension for ASP.NET application on IIS?[Top]
Here is the answer:
· In the IIS 6 case:
1. Open IIS 6 Management and enter website’s Properties page
2. Click Configuration on the Home Directory tab
3. Click Insert to open Add/Edit Application Extension Mapping
4. Browse aspnet_isapi.dll (By default, it is in \%windows%\microsoft.net\framework\v2.0.50727\ folder.) in the Executable textbox and uncheck Verify File Exists
5. Click OK
· In the IIS 7 Classic mode case:
1. Open IIS 7 Management
2. Choose Handler Mapping in IIS section
3. Click Add Wildcard Script Map to open Add Wildcard Script Mapping
4. Browse aspnet_isapi.dll (By default, it is in \%windows%\microsoft.net\framework\v2.0.50727\ folder.) in the Executable textbox and type the name you want
5. Click Yes
Note: There is no need to configure wildcard for IIS 7 Integrated mode.
For more information about configuring wildcard on IIS, please visit the following website: http://learn.iis.net/page.aspx/508/wildcard-script-mapping-and-iis-7-integrated-pipeline/