私はブラウザのキャッシュの問題を解決しようとしています。 jsファイルとcssファイルのいずれかに変更があった場合、ファイルはサーバーではなくブラウザのキャッシュから提供され、インターネット上で再検索され、mads krinstinsenのthis great postが見つかりました。ASP.Netキャッシュ破損アプローチが機能しない(更新済み)
私はApp_Code
フォルダのクラスに次のクラスとメソッドを含めました。
using System;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
public class Fingerprint
{
public static string Tag(string rootRelativePath)
{
if (HttpRuntime.Cache[rootRelativePath] == null)
{
string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
int index = rootRelativePath.LastIndexOf('/');
string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
}
後で、以下のように、私のすべてのaspxページ(ほぼ500箇所)の参照を変更しました。
<script type="text/javascript" src="<%=Fingerprint.Tag("/Scripts/JQuery/jquery.color.js")%>"></script>
<script type="text/javascript" src="<%=Fingerprint.Tag("/Scripts/JQuery/jquery.glowbuttons.js?v=1.1")%>"></script>
私はまた、次の書き換えルールを追加し、IISに書き換えモジュールをインストールしました。
<rewrite>
<rules>
<rule name="fingerprint">
<match url="([\S]+)(/v-[0-9]+/)([\S]+)" />
<action type="Rewrite" url="{R:1}/{R:3}" />
</rule>
</rules>
</rewrite>
今私は
このすべてを直面しています問題は、私の開発環境に魅力を働いていました。 iis(uatと私のローカルiis)にコードを公開したとき、同じコードが機能しませんでした。
Fingerprint.Tag()
メソッドは、間違ったURLを返します。
以下
http://localhost:54992/login.aspx
私のIIS WebサイトのURLは、あなたは、IIS上でこれをURLセグメント(\myClientName\)
の余分なレベルに気づいたかもしれません
http://www.example.com/myClientName/login.aspx
のようになりますように私の開発URLが行きます問題の原因となっています。
また、URLにmyClientName
の部分を追加するロジックを追加しましたが、残念ながらそれも機能しませんでした。
IISでホストされているWebサイトでは、URLパスがmyClientName部分をスキップするため、404エラーが発生しました。
UPDATE 1
Iはまた、コードはそれに応じて
public static string Tag(string rootRelativePath)
{
if (rootRelativePath.Contains("~"))
rootRelativePath = rootRelativePath.Replace("~", string.Empty);
bool isRunningInIisExpress = Process.GetCurrentProcess()
.ProcessName.ToLower().Contains("iisexpress");
if (HttpRuntime.Cache[rootRelativePath] == null)
{
string siteAlias = string.Empty;
if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["SiteName"]))
siteAlias = WebConfigurationManager.AppSettings["SiteName"].ToString();
string absolute = HostingEnvironment.MapPath("~" + rootRelativePath);
DateTime date = File.GetLastWriteTime(absolute);
int index = rootRelativePath.LastIndexOf('/');
string result = rootRelativePath.Insert(index, "/v-" + date.Ticks);
if (!isRunningInIisExpress)
{
siteAlias = "/" + siteAlias;
result = siteAlias + result;
}
if (File.Exists(absolute))
HttpRuntime.Cache.Insert(rootRelativePath, result, new CacheDependency(absolute));
}
return HttpRuntime.Cache[rootRelativePath] as string;
}
経路をiisexpressまたはフルIIS上で実行して生成されたかどうかを確認する同じ方法の後に別のバージョンでそれを試してみました私が間違ったことを指摘してくれた、正しい方向へ私を導いてください。
書き換えルールを適用するとどうなりますか?デベロッパーのパスは同じになりますか? – Dexion
@Dexion –
Devjosh
はいのような意味ですか?私はiis/siteの設定を比較することをお勧めします。 – Dexion