【问题标题】:Custom provider in the url rewrite moduleurl 重写模块中的自定义提供程序
【发布时间】:2014-08-18 09:29:00
【问题描述】:

我正在一个网站上进行开发,该网站目前托管在 Azure 上的 VM 上。现在我正在更改此网站,以便能够将其作为 Azure 网站运行。

现在我的问题: 我正在使用来自 IIS 的 url 重写模块和数据库提供程序,它在 VM 中完美运行。通过网站的数据库提供商,用户可以创建自己的简单重写规则。

但是当我将我的网站作为 Azure 网站上传并访问数据库中指定的 url 时,我收到一个错误:

“由于发生内部服务器错误,页面无法显示。”。

这是我目前使用的日志配置:

<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>

我打开了没有给我任何信息的网络服务器日志记录,我也启用了也没有给我任何信息的应用程序日志记录。

我的问题,是否可以在 Azure 中为 url rewite 模块使用自定义提供程序,这可以通过其他方式实现吗?

【问题讨论】:

  • 你解决过这个问题吗?

标签: azure url-rewrite-module


【解决方案1】:

我遇到了同样的问题:DbProvider 在 azure Web 应用程序中不可用。因此,我将web.config 中的大部分url 重写内容保持不变,并将基于数据库的规则移至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);
        }
    }
}

【讨论】:

    猜你喜欢
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-29
    • 2013-01-01
    • 2014-02-19
    • 2019-11-23
    • 1970-01-01
    相关资源
    最近更新 更多