Home Page

 

Computers

 

Developer

asp.net

There are some things you need to do first, in order to use ASP.Net with IIS.

In order to use asp.net with newly installed IIS:
"C:\<%System Root%>\Microsoft.NET\Framework\<curr.ver.>\aspnet_regiis.exe -i"

Web Project can be taken Offline.


Virtual Folders:

To create a web application in a folder out of wwwroot, read below or visit the original article.

Creating an ASP.NET Web Application in a physical folder of your choice
When you create a new ASP.NET Web Application, VS.NET by default creates a folder with the specified application name under the Visual Studio Projects folder (typically under :\Documents and Settings\\My Documents\Visual Studio Projects), and a folder with the same name under :\Inetpub\wwwroot. In the first folder it creates just the solution files (.sln and .suo), while all the ASP.NET project's source files (.aspx, .vb, .config etc.) go into the second folder.

However, you usually want to keep all your projects under a common folder, and have the source files together with the solution files (so that's easier to move everything to another computer, for example), whether they are Windows or Web application, and thus don't like VS.NET's default behavior. It would be preferable to have the possibility to specify a virtual and a physical folder when you create the web application, but unfortunately this is not possible from the New Project dialog window.

The solution is easier than what you may think, though. Say that you want to create a web application named MyWebTest, and that you want to place all the source files (not just the solution files) under c:\My Projects\MyTestWeb. Here are the steps to follow:

  1. Create a Blank Solution in c:\My Projects\MyTestWeb, so that the solution files will be placed in a new folder with this name and in this location.
  2. From the IIS administration console create a new virtual directory named MyTestWeb that points to the physical folder created above. (Alternatively, you can create the virtual folder from Windows Explorer, through the Web Sharing page of the Properties dialog for the physical directory.)
  3. Add a new project of type ASP.NET Web Application to the blank solution, and in VS.NET's New Project dialog use MyWebTest as project name. VS.NET recognizes that a virtual folder with that name is already present, and use it for the project, even if it points to a physical location that is different to that VS.NET would have used by default.
Marco Bellinaso

My notes:

In addition to this, you need to allow anonymous access with IIS (Properties -> Directory Security -> Anonymous Access) if you want to be able to access this application through web browser. Then, add IUSR_<hostname> to ACL.
To be able to debug such an application or run it, allow user ASPNET access to the folder, as well. Or add the ASPNET user to Administrators group, as some people suggest.
The default permissions are OK, no need to tweak additionally. The permissions need to propagate to child objects as well (files inside the application folder).

You may also need to enable the Front Page extensions - to make a subweb - for the application in the IIS, to be able to open it in Visual Studio.


Asp.net is installed by starting
"C:\<%System Root%>\Microsoft.NET\Framework\<curr.ver.>\aspnet_regiis.exe -i"


In order to use Forms authentication, enable Integrated Windows Authentication for the web site (or all sites): Properties -> Directory Security -> Anonymous Access: Edit. Forms authentication is independent of IIS Security. It is better suited to general Internet use.

The drawback is that it only affects dotNet registered pages, meaning .aspx. Ordinary html or other documents can not be protected by it.
Authenticated user receives authentication ticket as a cookie. The authentication ticket lifetime can be controlled.
In <authorization> section, <deny users="?" /> means that only authenticated users are allowed. The authorization can also only allow certain users and deny all the other.
The authorization by listing users in the web.config file is not realistic. The user data can be stored in a database. Allow only letters and numbers in text boxes related to authentication. For security, use stored procedures to check users' authorization from a database.

Timeout attribute is expressed in minutes and marks the time after which the session authentication will become invalid. Session cookie is automatically prolonged during subsequent calls if the cookie's lifetime is more than half over.

In order to customize access to subfolders of your application, Web.config files in these sub-folders must not contain the following sections: <authorization>, <sessionState>.


Some useful examples:

Creating a default button for the pageviewstate

Application deployment to production serverMoving asp.net projects to personal foldersmove project to another computer

SelfSSL


ViewState is not relevant to client-side page display.


SSL: Microsoft has released IIS Resource Kit Tools that contain SelfSSL, which can be used to issue SSL certificates.
Do not use /T, although it sounds nice, because you may have problems connecting to SQL Server afterwards! :)


Copy/Deployment: Visual Studio offers an option to Copy Project files to another location. This option can be used to separate distributable files - dlls, aspx, and other - from source code files. It will also do everything it can to create the new web site. If source files are excluded, the copy is the 'clean' copy of the site, ready for deployment. The target host needs to be running FrontPage Extensions.
If deployment is performed through XCopy option, the IIS needs to be configured additionally. This involves creation of a Virtual Directory, pointing to our application folder. Default permissions are all right (read, script). Web.config takes care of the configuration from there.


Localization: use .resx files to create strings in different languages. Compile them with ResGen. Load these files with code and set labels to contain those strings.


Mozilla Firefox: The ASP.Net is sending a faulty HTML to Mozilla Firefox browser. This can be fixed by adding BrowserCap either to machine.config (for the whole web site) or to web.config (for one application).


<body> tag manipulation: In order to manipulate tags not directly available in asp.net, like <body>, HtmlGenericControl is available.
First set <body id="body" runat="server"> in the page template, then use
HtmlGenericControl body = (HtmlGenericControl) this.FindControl("body");
body.Style.Add("DIRECTION", "rtl");
in the code. There you can set the style, or whatever you need.


PDF: PDF can easily be exported from Crystal Reports page, with only a few lines of code.


Web.config: This file can be used to store connection string. Add something like the following:

<configuration>
...
<appSettings>
  <add key="serverName" value="diomedes" />
</appSettings>
...
<system.web>
...
</system.web>
</configuration>

and then, simply, reference the settings like this:

x = System.Configuration.ConfigurationSettings.AppSettings("serverName")

Unicode: Firefox can be used to debug asp.net applications, but asp.net pages must not be saved as Unicode. Unicode (UTF-8) with Signature is the format that will both store the international characters and allow Firefox to act as a client. Otherwise, Firefox will not be able to send _doPostBack() message.


Page processing:

Stage Meaning Typical uses
ASP.NET Page Framework Initialization The page's Page_Init event is raised, and the page and control view state are restored. During this event, the ASP.NET page framework restores the control properties and postback data.
User Code Initialization The page's Page_Load event is raised. Read and restore values stored previously:
  • Using the Page.IsPostBack property, check whether this is the first time the page is being processed.
  • If this is the first time the page is being processed, perform initial data binding.
  • Otherwise, restore control values.
  • Read and update control properties.
Validation The Validate method of any validator Web server controls is invoked to perform the control's specified validation. (There is no user hook at this stage. You can test the outcome of validation in an event handler.)
Event Handling If the page was called in response to a form event, the corresponding event handler in the page is called during this stage. Perform your application-specific processing:
  • Handle the specific event raised.
    Note   Events are not raised in a particular order, except that cached control events — as specified by the control's AutoPostBack property — are always processed before the posting event.
  • If the page contains Types of Validation for ASP.NET Server Controls, check the IsValid property for the page and for individual validation controls.
  • Manually save the state of page variables that you are maintaining yourself.
  • Check the IsValid property of the page or of individual validation controls.
  • Manually save the state of controls dynamically added to the page.
Cleanup The Page_Unload event is called because the page has finished rendering and is ready to be discarded. Perform final cleanup work:
  • Closing files.
  • Closing database connections.
  • Discarding objects.
    Note   It is important that expensive resources, such as database connections, be explicitly closed. Otherwise, they will remain open until the next garbage collection occurs. On a heavily loaded server, many open resources can adversely affect performance.

Textboxes in Firefox: By default, the server-side TextBox displayed in Firefox, will be about 100px wide. Setting width to 100% will display it properly in Internet Explorer but not in Firefox.
The solution to this is to define a CSS class with width 100% and set CssClass property to it. It works with Firefox!


Data Binding: Asp.Net supports data binding only for data display. Update procedure has to be coded manually.

When binding data list, a DataReader can be set as a DataSource. Controls (items) within data list need to be bound to Container data values, not directly to a dataset, unless the appropriate result is actually wanted. :)

Since data binding is used only for data display, there are two stages in editing data. The first is in Page_Load and includes loading data and binding data controls in order to display the data. The second stage is in saving data. On cmdSave_Click the data is loaded again, row that contains the edited data is selected (dataset.table.rows[0]), the row data is set to values in data controls manually, and then the data is updated via data adapter.update(dataset, table). That's it.


Web server is located at C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\

It is started by Visual Studio in the following way:

"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE" /port:4011 /path:"C:\Alen\Visual Studio 2005\WebSites\TestWebSite" /vpath:"/TestWebSite"

Usage: WebDev.WebServer /port: <port number> /path: <physical path> [/vpath: <virtual path>]

port number: [Optional] An unused port number between 1 and 65536. The default is 80 (usable if you do not also have IIS listening on the same port).

physical path: A valid directory name where the Web application is rooted.

virtual path: [Optional] The virtual path or application root in the form of '/<app name>'. The default is simply '/'.


asp.net online

Developing projects with Cassini

Cassini and Apache

IIS

asp.net projects

links

Have a look at asp.net for a great site on asp.net. Microsoft has offered a free IDE for asp.net and there is a source for the web server that hosts asp.net. There are also forums, texts and electronic books on the topic that you can read online.


Here are tips for starting the project with Cassini

1. Create a directory for your new project
- i.e. c:\develop\test
2. Start the Cassini web server with
webserver /port:80 /path:"c:\develop\test" /vpath:"/test"
3. Create a new ASP .NET Web app at
http://localhost/test


Add the following lines to httpd.conf to use Cassini with Apache web server:

################################################################
# Configuration Cassini
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule rewrite_module modules/mod_rewrite.so

# Configuration Cassini
#ProxyPass /aspnet http://127.0.0.1:8080/
ProxyPass / http://127.0.0.1:8080/
#ProxyPassReverse /aspnet http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

################################################################


IIS can be configured on some other port and used for development, while Cassini can be configured with apache to use the application being developed.


Asp.net project pages should use Unicode in order to display Bosnian characters. On the client side Internet Explorer can be used because it supports Unicode characters.

Cassini can host only one application per instance. That's why the server needs to be started for every virtual directory ie. application. Each application then has it's own web.config, Global.asax and other configuration files.

Server root directory needs to contain aspnet_client directory with some js scripts in order to perform Forms Authentication.


Links to some useful sites:

Orcs,