1
我在我的網站(ASP.NET 4.0/IIS6)上使用url重寫,而不是我使用html的aspx。這裏描述的一切:IIS 6 executing html as aspx。問題是,當我在網站上有任何真正的.html文件(網站文件夾中存在html文件)時,它不會在網絡瀏覽器中打開。這是解決這個問題的方法嗎?謝謝!IIS 6,html文件/擴展名,urlrewriting
我在我的網站(ASP.NET 4.0/IIS6)上使用url重寫,而不是我使用html的aspx。這裏描述的一切:IIS 6 executing html as aspx。問題是,當我在網站上有任何真正的.html文件(網站文件夾中存在html文件)時,它不會在網絡瀏覽器中打開。這是解決這個問題的方法嗎?謝謝!IIS 6,html文件/擴展名,urlrewriting
您可以使用這樣一個自定義的HttpModule:
public class CheckRealHtmlFile : System.Web.IHttpModule
{
public void Dispose()
{
}
public void Init(System.Web.HttpApplication context)
{
context.BeginRequest += new EventHandler(context_BeginRequest);
}
void context_BeginRequest(object sender, EventArgs e)
{
System.Web.HttpApplication app = sender as System.Web.HttpApplication;
if (app != null)
{
System.Text.RegularExpressions.Regex rHtml = new System.Text.RegularExpressions.Regex(@"\.html$", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (rHtml.IsMatch(app.Context.Request.Url.AbsolutePath) && !System.IO.File.Exists(app.Context.Server.MapPath(app.Context.Request.Url.AbsolutePath)))
{
//Execute your html -> aspx logic
}
else
return;
}
else
return;
}
}
「還需要注意的是,如果你想擴展映射到不存在的文件(例如,如果你是URL重寫),你是非常重要的必須確保取消選中說明驗證文件是否存在的框。「 – 2012-02-11 23:35:37
是的,我做了,問題是,當文件(html)存在時,我需要在瀏覽器中打開它。 – ihorko 2012-02-12 07:14:59
你說它不能在網頁瀏覽器中打開。你的意思是它被下載,而不是它根本沒有響應,或者你得到一個服務器錯誤(404/500)? – 2012-10-11 16:25:39