Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

IIS Redirection with Page and Query String (UPDATED)

By default IIS redirects to a given domain and/or application.
The web page and query string can be transferred to the destination url by using the respective parameters $S and $Q.

Ex.
template: http://example.com$S$Q
redirection from
http://old-example.com/default.aspx?id=1
will lead to
http://example.com/default.aspx?id=1

In IIS 6 the checkbox "Exact Url" will avoid appending the web page to the query string.

UPDATE:
In order to achieve that behaviour in IIS 7 you have to first enable "Redirect all requests to exact destination" and append the sufix $S$Q to the url.
If you rely in the automatic url redirection of IIS (by default, w/o $S$Q in url) the query string is actually cut.

IIS Url Rewriting - avoid repeat of querystring parameters

Using the URL rewriting mechanism of IIS causes repeat of querystring parameters on every postback, because it builds the postaback url (rewrites url) by appending the querystring to current url.

Actual url:
/product.aspx?type=hats

Rewritten url:
/product/hats

Rewritten url after postback:
/product/hats?type=hats
which is actually equal to /product.aspx?type=hats&type=hats
So the type value is "hats,hats".

To avoid repeat of querystring variables simply check if the url is already rewritten:

protected void Page_Load(object sender, EventArgs e)
{
if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
{
form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
}
}

Detailed description:

SQL Server Express and IIS: Failed to generate a user instance of SQL Server due to failure in retrieving the user's local application data path.

SQL Express user instancing fails with the default IIS 7.x configuration. To solve this you can do the following:

1. Create new application pool in IIS
2. Open Application Pool Advanced settings
3. Change Identity from ApplicationPoolIdentity to NETWORK SERVICE and confirm
4. Change the application pool that the web application belongs to by opening Advanced setting of the web application

How to get the value of the server variable LOGON_USER

1. Uncheck Allow Anonymous in the security tab of the site properties in IIS. At least Basic or Windows Authetication is needed.

2. Use the variable Request.ServerVariables("LOGON_USER") to get the full user name

How to map an extension for server side scripting - html to php

Sometimes we need including some functionality or server includes into static web files - html. But changing the extension can lose current search engine index and rank. That is why leaving the fiels with the same name is the better way. Easy html files can be mapped to be parsed as php file.

IIS 7.0:
1. Open IIS Management Console
2. Open Web-site node
3. Open Handler Mapping
4. Add the extension as request path (*.html)
5. Set the handler application/library: something like C:\Program Files\PHP\php5isapi.dll
6. Name it and click OK

Apache:
Just add the following row in the .htaccess file:
AddType application/x-httpd-php .html

Error reporting in PHP run on IIS

The PHP error reporting is controlled either by the php.ini file as a global setting or programatically, or using .htaccess.

The error reporting in php.ini is defined in "Error handling and logging" section.
  • error_reporting = E_ALL & ~E_NOTICE - shows all errors except E_NOTICE errors. E_NOTICE are possible errors which can occur even during normal program workflow - something like Microsoft's warnings.
  • display_errors = On
  • display_startup_errors = On
Programmatically the same settings are applied for current site like this:
ini_set('display_errors','1');
ini_set('display_startup_errors','1');
error_reporting(E_ALL & ~E_NOTICE);

In .htaccess the flags must be changed in the following way:
php_flag display_errors 1
php_flag display_startup_errors 1


Php error_reproting help -> http://php.net/error_reporting

Get UrlRewritingNet to work with IIS 7.0

There is a well known problem using url rewriting functionality with UrlRewritingNet and IIS 7. The problem can be solved by setting the pipeline mode of the application pool to be in classic mode. Looking forward for the next version :).
Actually the url rewriting functionality can be achieved much easier with IIS 7.

Page Cannot Be Found Issue on IIS 6 on Windows 2003

Also:
HTTP 404 - File not found

First of all be sure that the default document list contains the page you are requesting (IIS -> Server Node -> Site node -> right mose click -> Properties -> Documents
Also set the necessary permission to the web folder (NETWORK SERVICE must have read/write rights)
Check if the asp.net status is allowed (IIS -> Server Node -> Web Service Extensions -> Asp.net must be allowed). This can be done during the installation of IIS.

How to set up SMTP Virtual Server with IIS

Exception: Mailbox unavailable. The server response was: 5.7.1

Check the following settings in IIS

IIS -> Default SMTP Server -> Properties -> Access
1. Authentication -> Anonymous access -> Checked
2. Connection control -> Only the list below -> Add current web server ip
Relay restrictions > Relay > - Only the list below -> Add current web server ip

Also add localhost ip here 127.0.0.1 . If DNS lookup doesnt work you can add alias for 127.0.0.1 in your
C:\WINDOWS\system32\drivers\etc\hosts file.

Also it is necessary to have these lines in web.config


<system.net>
<mailsettings>
<smtp deliverymethod="network" from="user@domain.com">
<network host="localhost" port="25" defaultcredentials="true">
</network>
</smtp>
</mailsettings>
</system.net>