没有选项(已知或记录在案 - 可供公众使用)来更改 aspsessionids(经典 asp)的名称。
您可以从 IIS 或使用 @ENABLESESSIONSTATE 指令禁用会话(ASP -> 会话属性 -> 启用会话状态: false),然后继续使用由 asp(而不是 JavaScript)提供的您自己的 cookie。但只有当您的应用程序中不需要会话对象时,这才可以。
更好的方法是使用 Regex(Anthony W Jones 已经提供了 ASP 版本)或 .net(最小简化的 C# 示例)来更改日志文件中的这些“字符串”:
Regex rx = new Regex("ASPSESSIONID[A-Z]+=");
string log = rx.Replace(File.ReadAllText("u_ex120618.log"), "ASPSESSIONID=");
Console.WriteLine(log);
有关 aspx 和 IIS 的更多信息
一种选择是使用处理程序来删除标头。
public class RemoveHttpHeadersModule : IHttpModule
{
public RemoveHttpHeadersModule()
{
}
public void Dispose()
{
}
public void Init(HttpApplication context)
{
if (context != null)
context.PreSendRequestHeaders += this.OnPreSendRequestHeaders;
}
[SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Web.HttpResponse.#get_Headers()")]
private void OnPreSendRequestHeaders(object sender, EventArgs e)
{
try
{
HttpContext.Current.Response.Headers.Remove("ETag");
HttpContext.Current.Response.Headers.Remove("Server");
HttpContext.Current.Response.Headers.Add("Server", "my server");
}
catch (HttpException)
{
throw;
}
}
}
另一种选择是控制 global.asax 中的所有内容(代码或编译库) - 涵盖您无权访问 IIS 管理器的情况。
删除(和/或添加)标头:
protected internal void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("ETag");
HttpContext.Current.Response.Headers.Remove("Server");
}
处理错误
protected internal void Application_Error(object sender, EventArgs e)
{
// get the error code
int ec = ((HttpException)HttpContext.Current.Error).GetHttpCode();
// get the request path
// string req = HttpContext.Current.Request.Path;
// *** I suggest you to log the error before moving on
// clear the error to avoid IIS actions
HttpContext.Current.Server.ClearError();
if (ec == 404)
{
// do what ever you want
}
// ... add other error codes handling;
}
下一步是隐藏 aspx。
假设我们希望 .aspx 页面呈现为 .html 这在这里得到解答:将 .html 映射到 IIS7 中的 ASP.NET 管道的正确方法是什么 https://stackoverflow.com/questions/890814/what-is-the-proper-way-to-map-html-to-the-asp-net-pipeline-in-iis7
只需注意选择正确的框架版本即可。如果您无权访问 IIS 管理器,请修改您的 web.config(仅提供此任务所需的内容):
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="htmlpipe" path="*.html" verb="*" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" preCondition="classicMode,runtimeVersionv4.0,bitness64" />
</handlers>
</system.webServer>
</configuration>
上述设置可能会因您的 PC、服务器等而异。拥有具有相同基本属性(框架版本、32/64 位)的测试环境,在 IIS 中进行更改,然后检查 web.config 中生成的条目。
请允许我开个玩笑。 “你喜欢这个产品?”
谢谢弗兰克,你插入了一些旧磁盘并找到了被遗忘的东西。很抱歉没有提供经典 ASP 的建议。
附言。不要忘记HackedByChinese的回答。