use*_*553 6 azure url-rewrite-module
我正在一个网站上开发,该网站目前在VM上托管在Azure上.现在我正在更改此网站,以便能够将其作为Azure网站运行.
现在我的问题:我正在使用IIS中的url rewrite模块和数据库提供程序,它在VM中运行良好.使用数据库提供者,网站的用户可以创建自己的简单重写规则.
但是当我将我的网站上传为Azure网站并访问数据库中指定的网址时,我收到错误消息:
"由于发生内部服务器错误,无法显示页面."
这是我目前使用的日志配置:
<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>
Run Code Online (Sandbox Code Playgroud)
我打开了Web服务器日志记录,它没有给我任何信息,我启用了应用程序日志记录,但也没有给我任何信息.
我的问题是,是否可以在Azure中使用自定义提供程序用于url rewite模块,这可以通过其他方式实现吗?
我遇到了同样的问题:DbProvider 在 azure web 应用程序中不可用。因此,我保留了大部分 url 重写内容,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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
477 次 |
| 最近记录: |