1

In order to redirect old URLs to new one, I set up a DbProvider inside the Default Web Site in IIS 7.5 in Windows 7 (in production it will be under IIS 8 in Windows Server 2012 R2). Here's my configuration in web.config of Default Web Site (so that each application inside it can inherit it:

    <rewrite>
        <providers>
            <provider name="LORYDB" type="DbProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f">
                <settings>
                    <add key="ConnectionString" value="Driver={SQL Server Native Client 10.0};Data Source=localhost\sqlexpress;Initial Catalog=RewriteDB;Integrated Security=True;Server=localhost;uid=sa;pwd=xxxxxx" />
                    <add key="StoredProcedure" value="GetRewrittenUrl" />
                    <add key="CacheMinutesInterval" value="0" />
                </settings>
            </provider>
            <provider name="LORYMAP" type="FileMapProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f" />
            <provider name="LORYCONTAINER" type="FileContainsProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f" />
        </providers>
        <rules>
            <rule name="DbProviderTest" stopProcessing="true">
                <match url="(OmniService/foto/([0-9]+)-([0-9]+).jpg)" />
                <conditions>
                    <add input="{LORYDB:{R:1}}" pattern="(.+)" />
                </conditions>
                <action type="Redirect" url="{C:1}" />
            </rule>
        </rules>
    </rewrite>
    <tracing>
        <traceFailedRequests>
            <add path="*">
                <traceAreas>
                    <add provider="ASP" verbosity="Verbose" />
                    <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                    <add provider="ISAPI Extension" verbosity="Verbose" />
                    <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI" verbosity="Verbose" />
                </traceAreas>
                <failureDefinitions statusCodes="500" />
            </add>
        </traceFailedRequests>
    </tracing>

I am quite sure all the parameters are correct, overall the string connection and the stored procedure because I tried to call them by a simple python script and they work fine. Moreover, also the RegEX espression is correct because IIS detects and splits the URL (which, in test phase, are of this form: http://localhost/OmniService/foto/18443151-810079.jpg) correctly. But, in the browser I get a HTTP 500 error. So, I enabled the module Failure Request Tracing in IIS and I get a very complex .xml file from which I can see that the error is 500.50 which directly concerns the rewrite/redirect module but I don't know exactly where the problem is. If you want to have a look at the xml file you can read it here. Reading some docmentation, I found out that error is raised when the group IIS_IUSRS does not have full control on C:\Windows\Temp. I gave those permission to it but nothing has changed. I would really need to exactly understand where the problem is.

For example, this simple python sripts works:

import pypyodbc
if __name__=='__main__':
    connection=pypyodbc.connect("Driver={SQL Server Native Client 10.0};Data Source=localhost\sqlexpress;Initial Catalog=RewriteDB;Integrated Security=True;Server=localhost;uid=sa;pwd=working2014")
    cursor=connection.cursor()
    cursor.execute("exec RewriteDB.dbo.GetRewrittenUrl @input='OmniService/foto/18443151-810079.jpg'")
    print cursor.fetchone()

and I get 'OmniService/foto/2017/02/02/18443151-810079.jpg'

which is the correct new URL.

Thank you all.

UPDATE

I don't know why, but this part of the connection string Driver={SQL Server Native Client 10.0}; is not allowed with .NET Framework as this exception is raised:

System.ArgumentException: Parola chiave 'driver' non supportata. in System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey) in System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules) in System.Data.SqlClient.SqlConnectionString..ctor(String connectionString) in System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous) in System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(String connectionString, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions) in System.Data.SqlClient.SqlConnection.ConnectionString_Set(String value) in System.Data.SqlClient.SqlConnection.set_ConnectionString(String value) in System.Data.SqlClient.SqlConnection..ctor(String connectionString) in DbProvider.Rewrite(String value) in Microsoft.Web.Iis.Rewrite.RewriteProviderManager.InvokeProviderUnicode(String providerName, String providerInput)

I thought to test it with another framework (Instant Developer) which translates the code you write into web application based on .NET Framwork. I don't know why, as unfortunately I have no experience with .NET Framework...anyway, it might be a starting point

SagittariusA
  • 5,289
  • 15
  • 73
  • 127
  • Possible duplicate of [Deploying website: 500 - Internal server error](http://stackoverflow.com/questions/5385714/deploying-website-500-internal-server-error) – CodeCaster Feb 13 '17 at 13:42
  • Already tried and it did not help. – SagittariusA Feb 13 '17 at 13:55
  • It definitely does. If you correctly configure your webserver for debugging as explained in that question, you'll see the actual exception message. – CodeCaster Feb 13 '17 at 13:56
  • @CodeCaster: sorry but there's no way...maybe I have some other issue. For the moment I discovered this `Driver={SQL Server Native Client 10.0};` is not allowed in a string connection using .NET framework in this method `System.Data.Common.DbConnectionOptions` – SagittariusA Feb 13 '17 at 14:11

0 Answers0