Custom Provider in URL Rewriter

I am developing a site that is currently hosted on Azure in a virtual machine. Now I am changing this website to be able to run it as an Azure website.

Now my problem: I am using the url rewrite module from IIS with a database provider that works fine in VM. Using a database provider, website users can create their own simple rewrite rules.

But when I load my site as an Azure Website, and I access the URL provided in the database, I get an error:

"The page cannot be displayed because an internal server error has occurred.".

This is the logging configuration that I am currently using:

<rewrite>
  <rules configSource="RewriteInbound_Live.config" />
  <outboundRules configSource="RewriteOutbound_Live.config" />
  <providers>
    <provider name="DB" type="DbProvider, Microsoft.Web.Iis.Rewrite.Providers, Version=7.1.761.0, Culture=neutral, PublicKeyToken=0545b0627da60a5f">
      <settings>
        <add key="ConnectionString" value="*****" />
        <add key="StoredProcedure" value="sp_GetRewrittenUrl" />
        <add key="CacheMinutesInterval" value="60" />
      </settings>
    </provider>
  </providers>
</rewrite>

-, , , .

: url Azure, ?

+4
1

: DbProvider -. web.config global.asax Application_BeginRequest.

Response.Redirect Redirect301. , HttpContext.Current.RewritePath.

, :

void Application_BeginRequest(Object sender, EventArgs e)
{
    //TODO: Cache sql queries
    string requestUrl = Request.FilePath;
    using (DBConn conn = new DBConn("GetRedirectUrl"))
    {
        conn["input"] = requestUrl;
        string res = conn.ExecuteScalar()?.ToString();

        if (!string.IsNullOrEmpty(res))
        {
            Response.Redirect301(res);
        }
    }


    //TODO: Cache sql queries
    using (DBConn conn = new DBConn("GetRewrittenUrl"))
    {
        conn["input"] = requestUrl;
        string res = conn.ExecuteScalar()?.ToString();

        if (!string.IsNullOrEmpty(res))
        {
            HttpContext.Current.RewritePath(res);
        }
    }
}
0

Source: https://habr.com/ru/post/1546276/


All Articles