ASPSESSIONID名称变更 [英] aspsessionid name change

查看:252
本文介绍了ASPSESSIONID名称变更的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript" language="javascript">
function setCookie()
{
    var path = '/', host = document.location.hostname;
    document.cookie = 'random=' + Math.floor(Math.random()*11) + '; path=' + path + ( host ? '; domain=' + document.location.hostname : "" ) ;
}
function readCookie()
{
    alert(document.cookie)
}
</script>

我的生活会简单得多,如果我有一个简单的方法来改变 ASPSESSIONID **** 只是的SessionID 在我的日志。是否有一个快速的方法来做到这一点...在Windows?必须有一个脚本,批处理文件,命令或东西,我可以作为新的日志文件计划每日任务运行。在这样的时候,我希望我能编程。建议表示欢迎,请!

My life would be a lot simpler if I had an easy way to change aspsessionid**** to just sessionid in my logs. Is there a quick way to do this ... in Windows? There must be a script, batchfile, command or something that I can run as a scheduled daily task on new logfiles. At times like this I wish I could program. Suggestions welcome please!

推荐答案

没有选项。(已知的或记录 - 向公众提供)来改变aspsessionids的名称(传统的ASP)

您可以禁用会话(ASP - >会话属性 - >启用会话状态:FALSE)从IIS或使用@ENABLESESSIONSTATE指令,然后继续用自己的饼干从ASP服务(而不是由JavaScript)。但是,这只是OK,如果你没有在应用程序所需要的会话对象。

You can disable the session (ASP -> Session Properties -> Enable Session State: false) from IIS or by using the @ENABLESESSIONSTATE directive and move on with your own cookies served from asp (and not by JavaScript). But this is OK only if you don't need the session object in your application.

有一个更好的办法是改变使用正则表达式在日志文件中,这些串(ASP版本已经是美元的安东尼·琼斯W¯¯psented p $)或.NET(最小简化C#示例):

A better approach is to change these "strings" in log files using Regex (asp version is already presented by Anthony W Jones) or by .net (minimal simplified C# sample):

Regex rx = new Regex("ASPSESSIONID[A-Z]+=");

string log = rx.Replace(File.ReadAllText("u_ex120618.log"), "ASPSESSIONID=");
Console.WriteLine(log);

更多关于ASPX和IIS

一种选择是使用一个处理程序来删除页眉。

One option is to use a handler to remove headers.

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中的一切(code或编译库) - 覆盖的情况下,你没有访问IIS管理器

Another option is to control everything in global.asax (code or compiled library) - covering the case you don't have access to IIS manager.

删除(和/或添加)标题:

Remove (and/or add) headers:

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。

The next step is to hide aspx.

假设我们希望我们的.aspx页presented为html的这是在这里得到解答:<一href=\"http://stackoverflow.com/questions/890814/what-is-the-proper-way-to-map-html-to-the-asp-net-pipeline-in-iis7\">What是映射的.html在IIS7 ASP.NET管道的正确方法

Assume that we want our .aspx pages presented as .html This is answered here: What is the proper way to map .html to the ASP.NET pipeline in IIS7

只是要小心选择正确的框架版本。如果您没有访问IIS管理器,然后修改你的web.config($ P $仅需要什么这个任务psenting):

Just take care to select the correct framework version. If you don't have access to IIS manager, then modify your web.config (presenting only what is needed for this task):

<?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,服务器等有具有相同基本属性测试环境(framework版本,32位/ 64位),使你的IIS中的变化,然后检查你的web.config所产生的入口

The above setting may differ to your pc, server etc. Having a testing environment with the same basic attributes (framework version, 32/64bit), make the change in your IIS and then check the generated entry in your web.config.

请允许我开个玩笑。 你喜欢这个产品吗?

Allow me to make a joke. "Do you like this product?"

感谢您弗兰克,你可以做一些塞老盘,发现被遗忘的东西。我很抱歉没有传统的ASP建议。

Thank you Frank, you made be plug some old disks and find things that were forgotten. I'm sorry for not having suggestions for classic ASP.

PS。不要忘记HackedByChinese答案。

PS. Don't forget the answer by HackedByChinese.

这篇关于ASPSESSIONID名称变更的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆