Don't redirect after setting a Session variable (or do it right)

the origional post is here: http://weblogs.asp.net/bleroy/archive/2004/08/03/Don_2700_t-redirect-after-setting-a-Session-variable-_2800_or-do-it-right_2900_.aspx

A problem I see over and over again on the ASP.NET forums is the following:
In a login page, if the user and password have been validated, the page developer wants to redirect to the default page. To do this, he writes the following code:
Session["Login"] = true;
Response.Redirect("~/default.aspx");
Well, this doesn't work. Can you see why? Yes, it's because of the way Redirect and session variables work.
When you create a new session (that is, the first time you write to a Session variable), ASP.NET sets a volatile cookie on the client that contains the session token. On all subsequent requests, and as long as the server session and the client cookie have not expired, ASP.NET can look at this cookie and find the right session.
Now, what Redirect does is to send a special header to the client so that it asks the server for a different page than the one it was waiting for. Server-side, after sending this header, Redirect ends the response. This is a very violent thing to do. Response.End actually stops the execution of the page wherever it is using a ThreadAbortException.
What happens really here is that the session token gets lost in the battle.
There are a few things you can do to solve this problem.
First, in the case of the forms authentication, we already provide a special redirect method: FormsAuthentication.RedirectFromLoginPage. This method is great because, well, it works, and also because it will return the user to the page he was asking for in the first place, and not always default. This means that the user can bookmark protected pages on the site, among other things.
Another thing you can do is use the overloaded version of Redirect:
Response.Redirect("~/default.aspx", false);
This does not abort the thread and thus conserve the session token. Actually, this overload is used internally by RedirectFromLoginPage. As a matter of facts, I would advise to always use this overloaded version over the other just to avoid the nasty effects of the exception. The non-overloaded version is actually here to stay syntactically compatible with classic ASP.
UPDATE: session loss problems can also result from a misconfigured application pool. For example, if the application pool your site is running is configured as a web farm or a web garden (by setting the maximum number of worker processes to more than one), and if you're not using the session service or SQL sessions, incoming requests will unpredictably go to one of the worker processes, and if it's not the one the session was created on, it's lost.
The solutions to this problem is either not to use a web garden if you don't need the performance boost, or use one of the out of process session providers.
Thanks to Frédéric Gareau for pointing that out.
UPDATE 2: Another thing that can cause similar problems is if your server has a name that contains underscores. Underscores are not allowed in host names by RFC 952 and may interfere with the ability to set cookies and thus to persist sessions.

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 4/19/2009 at 11:48 AM
Categories: Technologies
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (4) | Post RSSRSS comment feed

一篇不错的在C#下使用多态性的文章

 Polymorphism, Method Hiding and Overriding in C#

 Overview

One of the fundamental concepts of object oriented software development is polymorphism. The term polymorphism (from the Greek meaning "having multiple forms") in OO is the characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow a variable to refer to more than one type of object.

Example Class Hierarchy

Let's assume the following simple class hierarchy with classes A, B and C for the discussions in this text. A is the super- or base class, B is derived from A and C is derived from class B. In some of the easier examples, we will only refer to a part of this class hierarchy.

Inherited Methods

A method Foo() which is declared in the base class A and not redeclared in classes B or C is inherited in the two subclasses

    using System;
    namespace Polymorphism
    {
        class A
        {
            public void Foo() { Console.WriteLine("A::Foo()"); }
        }

        class B : A {}

        class Test
        {
            static void Main(string[] args)
            {
                A a = new A();
                a.Foo();  // output --> "A::Foo()"

                B b = new B();
                b.Foo();  // output --> "A::Foo()"
            }
        }
    }
     

The method Foo() can be overridden in classes B and C:

    using System;
    namespace Polymorphism
    {
        class A
        {
              public void Foo() { Console.WriteLine("A::Foo()"); }
        }

        class B : A
        {
              public void Foo() { Console.WriteLine("B::Foo()"); }
        }

        class Test
        {
            static void Main(string[] args)
            {
                A a;
                B b;

                a = new A();
                b = new B();
                a.Foo();  // output --> "A::Foo()"
                b.Foo();  // output --> "B::Foo()"

                a = new B();
                a.Foo();  // output --> "A::Foo()"
            }
        }
    }
     

There are two problems with this code.

  • The output is not really what we, say from Java, expected. The method Foo() is a non-virtual method. C# requires the use of the keyword virtual in order for a method to actually be virtual. An example using virtual methods and polymorphism will be given in the next section.
  • Although the code compiles and runs, the compiler produces a warning:

...\polymorphism.cs(11,15): warning CS0108: The keyword new is required on 'Polymorphism.B.Foo()' because it hides inherited member 'Polymorphism.A.Foo()'

This issue will be discussed in section Hiding and Overriding Methods.

Virtual and Overridden Methods

Only if a method is declared virtual, derived classes can override this method if they are explicitly declared to override the virtual base class method with the override keyword.

    using System;
    namespace Polymorphism
    {
        class A
        {
            public virtual void Foo() { Console.WriteLine("A::Foo()"); }
        }

        class B : A
        {
            public override void Foo() { Console.WriteLine("B::Foo()"); }
        }

        class Test
        {
            static void Main(string[] args)
            {
                A a;
                B b;

                a = new A();
                b = new B();
                a.Foo();  // output --> "A::Foo()"
                b.Foo();  // output --> "B::Foo()"

                a = new B();
                a.Foo();  // output --> "B::Foo()"
            }
        }
     }

Method Hiding

Why did the compiler in the second listing generate a warning? Because C# not only supports method overriding, but also method hiding. Simply put, if a method is not overriding the derived method, it is hiding it. A hiding method has to be declared using the new keyword. The correct class definition in the second listing is thus:

    using System;
    namespace Polymorphism
    {
        class A
        {
            public void Foo() { Console.WriteLine("A::Foo()"); }
        }

        class B : A
        {
            public new void Foo() { Console.WriteLine("B::Foo()"); }
        }

        class Test
        {
            static void Main(string[] args)
            {
                A a;
                B b;

                a = new A();
                b = new B();
                a.Foo();  // output --> "A::Foo()"
                b.Foo();  // output --> "B::Foo()"

                a = new B();
                a.Foo();  // output --> "A::Foo()"
            }
        }
    }

Combining Method Overriding and Hiding

Methods of a derived class can both be virtual and at the same time hide the derived method. In order to declare such a method, both keywords virtual and new have to be used in the method declaration:

            class A
            {
                public void Foo() {}
            }

            class B : A
            {
                public virtual new void Foo() {}
            }
     

A class C can now declare a method Foo() that either overrides or hides Foo() from class B:

            class C : B
            {
                public override void Foo() {}
                // or
                public new void Foo() {}
            }

Conclusion

  • C# is not Java.
  • Only methods in base classes need not override or hide derived methods. All methods in derived classes require to be either defined as new or as override.
  • Know what your doing and look out for compiler warnings.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 2/18/2009 at 10:42 AM
Categories: Technologies
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (8) | Post RSSRSS comment feed

写在25岁

早上醒来发现短信,MSN,QQ上都是朋友的祝福,很是感动

回到杭州就是感觉不一样。

 

25岁是一个里程碑。是承上启下的节点。

到了25岁就不能再孩子气,

到了25岁就不能再装做自己是不谙世事刚从学校出来的大学生

到了25岁就要开始承担更多的责任

到了25岁就要开始对当初的梦想做更实际的行动

 

同时,这个年纪也反应了我现在的生活状态和社会阶层。比下有余,比上不足

早就下决心要好好闯荡一番

而从今天起,要迈出真正的第一步

 

已经不再迷茫

已经决定不再漂泊

已经锁定未来发展目标

 

世上有可以挽回的和不可挽回的事,而时间经过就是一种不可挽回的事

就以同月同日生的村上春树的话段来纪念这逝去的25年吧

Currently rated 1.0 by 1 people

  • Currently 1/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 1/11/2009 at 11:28 AM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

年末总结

首先我想说北京彻底把我冰冻了,从身体到大脑。刚好,让我能够冷静下来,对这个多灾多难,跌宕起伏的366天做个小小总结。

08年去过的城市;坐过十六个航班,到访过杭州, 北京, 上海, 香港, Brisbane, Macky, Sydney 和 Canberra。遗憾的是因为金融危机东瀛之旅最终无限延期

08年做过的大事;悉尼反媒体不公正报道大游行,堪培拉保卫圣火运动,经历了整个SWIFT和MAC项目

08年的学业; 研究生课程稳步前进,通过微软认证技术专家MCTS WSS3.0 Con和MCTS MOSS 2007 Con

08年的事业;第一次升职,第一次出差,第一次常驻客户,第一次体验身边同事被裁员

08年的健康;从2月份身体彻底罢工到开始进行全面医治+运动,现在基本回到正轨

08年的改变:不再通宵,开始吃早饭,注意运动,开车上下班,定期去健身房,游泳,开始打网球

08年的感慨:自然的力量,西方的偏见,国人素质的参差不齐,国货质量的悲哀,澳洲移民局的无能,身边朋友开始有小孩,中国要强大

08年的个人问题;继续单身

------------------------------------------------------------------------------------------------------------

09年的八大目标

1. 实现单人日本之旅

2. 在2009年拿到MASTER学位

3. 保持身体健康

4. Canon 5D MKII

5. 继续提升网球技能

6. 考出MCPD WEB DEVELOPER

7. 工作上能比今年多出3成业绩

8. 学会蝶泳

Currently rated 4.5 by 2 people

  • Currently 4.5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 12/30/2008 at 12:18 PM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

也许很苍白

我最近一直没有写东西.不是没东西可写.相反,可以写的东西实在太多
很多事情的发生让我有点震撼 但我不会忘记这个月所经历的一切
- 考试成绩
期末考的成绩出来了.两个都是credit,对于第一个在全职工作情况下业余完成的学期,我还是比较满意的。financial accounting最后的考试让我小担心了一下,project management最后没有拿到D也是略有失望。不过。至少,所有关于研究生的事都走在正规上。还剩下最后5门课。2009年加油
- 罚单
收到生平第一张超速罚单,竟然是在清晨6点50码的路上超到60码,罚钱就算了。还硬生生地被扣去3点。祸不单行,没过几天因为在2 HOURS ZONE挺的太久再被开以罚单一张。162大洋就这样乖乖落入洲政府口袋。可恶。可恶
- Paint Ball
彩蛋枪的伤疤到现在还留着。。。中澳大混战还是很刺激的。。。就是天气实在太热。坚守阵地的时候都快要没有呼吸了。对于夺旗战非常有成就感。我也享受了回英勇献身(为减轻重量。没有任何武器飞奔到正中央夺旗,在接受枪林弹雨的洗礼之时,以自己的身躯挡住子弹让同伴拿得旗子回阵地)
- MCTS
拿到了职业生涯中第一张微软认证技术专家的证书。是关于windows sharepoint 3.0的。接下来还要考MOSS的和ASP.NET 3.5。 总之是好的开始
- 游泳,网球
坚持了两个多月的游泳开始有了成效,现在一般都可以一次连续游个800米,总共游个1.5公里了。对于几个月前对游泳的记忆还局限于小学的我来说,实属不易
平行蛙泳已经完全没有问题,海豚蛙可以游个50米左右休息一下,自由泳仍旧处在非常慢的样子。不过看着自己的蛙泳能和身边的自由泳游的一样快。还是欣慰的
从今天开始一周2次的网球课程。。。以前只跟着老妈在体校练习过羽毛球,网球完全是门外汉。ALEX竟然找来了ANDREW这个国际一级教练来教我们。很好很强大。第一节课正手反手都学了个雏形。有点学小球的基础。。。进度还挺快
- 搬家
下周末就要正式搬离KENSINGTON,去住RHODES的新居了。希望生活质量能有所提高吧
- 圣诞节
告知各位,因为公司重大变故,我回国的日程大幅调整至12月底到2月初
- 游戏
在EBAY上买的FABLE 2因为卖家寄丢东西,着实让我恼火了一阵
不过还是推荐有XBOX的人玩。至于PS3,入了一个抵抗2,只可惜我的PS3已经打包了,等搬家后再说吧
- 金融危机
公司在礼拜一宣布裁员,总共涉及人数接近1/3不到。。。剩下的还被多少扣掉了点薪水
很多早上还在一起奋战的TEAM MATE下午就要面临走的命运,我很难过
很多公司都大幅裁员。人人自危

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 11/26/2008 at 11:25 PM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (2) | Post RSSRSS comment feed

换季

发现工作以后就没有怎么好好静下心来读过一整本书 开始喜欢几百字的评论文章 没有时间去细细品味新的音乐 只是在开车的时候让IPOD胡乱SHUFFLE 甚至一部电影,要是有给我PAUSE的机会 大凡都会分好几次看完 是浮躁还是工作读书后的心疲力竭? 或是物质生活压力症在蚕食我的精神世界? 需要精神上的COOL DOWN 整理我想要的 我想成为的 我想面对的 时间越来越少 不再像大学里那样自由支配 一些不必要的爱好需要退化~ 一些不必要的娱乐需要缩减~ 也许经济危机来的正是时候,让我手头的资产贬值 警示我冒进的危险 提供我反思的空间 我呢,还在自己的世界慢慢爬行 会因为和朋友谈论公司的事情而踌躇满志 会因为在UNI里拿到一个HD的ASSIGNMENT而继续骗自己学术重要性 会因为写出一个优化的SQL QUERY而妄想自己是疯狂IT科学家 也会因为看一部单纯的海角七号而动摇自己画上红叉叉的爱情论 果然每个人都有自己的生命轨迹 COPY是不会成功的 唯有不断地自我修正了 晚上很凉,完全没有换季的感觉 澳洲的夏日没有知了叫 只有热热的海风

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 10/20/2008 at 11:26 AM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

拐点

听到最惹人厌的闹钟声~
把手机扔到杂乱不堪的卧房地毯上
迷迷糊糊地从床上起来
刷牙,洗脸,吃药
酸奶,苹果,饼干
背上沉重的笔记本
发动汽车让引擎预热
连上iPhone到汽车音响上
从口袋里拿出一盒清凉糖润喉
随着絢香的FOR TODAY的歌声
驶出小车库
向北悉尼驶去
大体每一天的开始就是这样
依旧是空空的副驾驶
依旧是蓝蓝的天
港湾大桥在早晨刺眼的阳光下显得陈旧而厚重
不远处若隐若现的歌剧院在时刻提醒我我依旧生活在这个不属于我的国度
所幸今天路上没有发生事故
可以按照70码以上的速度行走
穿过大桥,习惯性地右拐,窜进居民区的小路,找到路边空位停下,再往公司的方向走去
到门口一看表,还是迟到15分钟
不过算是老板可以忍受的范围
安全到垒
一个人就这样奔走了5年
一切看似顺利:不错的工作,不差的薪水,安逸的坏境,还在算是澳洲所谓最好的大学读硕士
我却开始陷入思考 难道自己追求的就是要这样平庸稳定地在澳洲工作下去么?
不对~这不是我的人生目标啦
看得越多越发觉自己的渺小
只是。。。不能因为艰难就放弃
毕竟是我自己选的路
未来的三年。。。
期待我人生的新拐点

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 10/14/2008 at 3:50 PM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

用递归来创建一个MAP到某本地地址的TREE VIEW,并复制用户选择的文件到指定目录

项目里用到了,觉得有必要记下来,不然琢磨了半天的成果又忘记了,控件用的是RAD TREE VIEW,理论都是相通的

CS端代码:首先是递归函数主体,先查找子目录,加为节点,再查找每个子目录下的文件,加为节点

 protected void BuildDirectoryTree(RadTreeNode parentNode)
        {
            // Handle Directories
            var directories = Directory.GetDirectories(parentNode.Value).Select(d => new RadTreeNode() { Text = d.Substring(d.LastIndexOf("\\")+1), Value = d });

            foreach (var directory in directories)
            {
                BuildDirectoryTree(directory);
                parentNode.Nodes.Add(directory);
            }

            // Handle Files
            var files = Directory.GetFiles(parentNode.Value).Select(f => new RadTreeNode() { Text = f.Substring(f.LastIndexOf("\\") + 1), Value = f });
            parentNode.Nodes.AddRange(files);          
        }

然后是调用,我直接拿项目里的做例子了:

protected void lbtnAddTemplate_Click(object sender, EventArgs e)
        {
            string quoteNo = Request.QueryString["QuoteNo"];
            HyperLink hlTemplateQuoteFolder = (HyperLink)quoteView.FindControl("hlTemplateQuoteFolder");
            RadTreeView rtvTemplateFilesList = (RadTreeView)quoteView.FindControl("rtvTemplateFilesList");

            if (!string.IsNullOrEmpty(quoteNo))
            {
                if (Directory.Exists(strTemplatePath))
                {
                    RadTreeNode rootNode = new RadTreeNode { Text = "Templates", Value = strTemplatePath };
                    BuildDirectoryTree(rootNode);

                    rtvTemplateFilesList.Nodes.Add(rootNode);
                }
            }

        }

TREE VIEW看起来像这样,然后当用户选中了他们要的文件后,选择添加会把这些文件拷到特定目录下(维持现在的位置)

protected void btnAddNewTemplate_Click(object sender, EventArgs e)
        {
            string message = string.Empty;
           
            RadTreeView rtvTemplateFilesList = (RadTreeView)quoteView.FindControl("rtvTemplateFilesList");
            IList<RadTreeNode> fileLst = rtvTemplateFilesList.CheckedNodes;

            // Create a QuoteNo folder
            if (!string.IsNullOrEmpty(QuoteNo))
            {
                string quotePath = Path.Combine(quoteRootPath, QuoteNo);
                // Check if the directory exists, if not then create it

                if (!Directory.Exists(quotePath))
                {
                    Directory.CreateDirectory(quotePath);
                }

                // Go through the list and copy all the files
                foreach (var item in fileLst)
                {
                    if (File.Exists(item.Value))
                    {
                        string relativeFolder = item.Value.Remove(item.Value.LastIndexOf("\\"));
                        if (relativeFolder.LastIndexOf("\\") < relativeFolder.Length - 1)
                        {
                            relativeFolder += "\\";
                        }
                        relativeFolder = relativeFolder.Replace(strTemplatePath, "");
                        string destinationFolder = Path.Combine(quotePath, relativeFolder);

                        if (!Directory.Exists(destinationFolder))
                        {
                            Directory.CreateDirectory(destinationFolder);
                        }
                        File.Copy(item.Value, Path.Combine(destinationFolder, item.Text),true);
                    }
                }
            }

            //hide the panel
            System.Diagnostics.Process.Start(@"c:\");
            AjaxControlToolkit.ModalPopupExtender mpAddNewTemplate = (AjaxControlToolkit.ModalPopupExtender)quoteView.FindControl("mpAddNewTemplate");
            mpAddNewTemplate.Hide();
               
            Response.Redirect("QuoteDetails.aspx?QuoteNo=" + QuoteNo);
        }

如果想把整个FOLDER包括里面所有东西拷贝到另一个地方的话,有一个METHOD更简单:

  protected void copyDirectory(string Src, string Dst)
        {
            // Copy directory structure recursively
            String[] Files;

            if (Dst[Dst.Length - 1] != Path.DirectorySeparatorChar)
                Dst += Path.DirectorySeparatorChar;
            if (!Directory.Exists(Dst)) Directory.CreateDirectory(Dst);
            Files = Directory.GetFileSystemEntries(Src);
            foreach (string Element in Files)
            {
                // Sub directories
                if (Directory.Exists(Element))
                    copyDirectory(Element, Dst + Path.GetFileName(Element));
                // Files in directory
                else
                    File.Copy(Element, Dst + Path.GetFileName(Element), true);
            }
        }

ASPX端代码:

                    <asp:Panel ID="pnlAddNewTemplate" runat="server" Width="280px" Height="200px" CssClass="popup">
                        <asp:UpdatePanel ID="updPnlAddNewContact" runat="server" UpdateMode="Conditional">
                            <ContentTemplate>
                                <div class="contact-inline">
                                    <span>Quote Folder - </span>
                                    <asp:HyperLink ID="hlTemplateQuoteFolder" runat="server" /></div>
                                 <telerik:RadTreeView ID="rtvTemplateFilesList" runat="server" CheckBoxes="true" OnClientNodeChecked="AfterCheck">    
                                </telerik:RadTreeView>
                                <asp:Label ID="test" runat="server" />
                                <div class="contact-inline">
                                    <asp:Button ID="btnAddNewTemplate" runat="server" Text="Add Template" OnClick="btnAddNewTemplate_Click" />
                                    <asp:Button ID="btnCancelNewTemplate" runat="server" Text="Cancel" OnClick="btnCancelNewTemplate_Click" />
                                </div>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </asp:Panel>

还要在旁边加上一个JAVA SCRIPT的函数,用来监测当CHILD NODE被选中的话,PARENT NODE也要被同时选上

<%--If the node is checked, the childs of this node will also be checked--%>
                                 <script type="text/javascript">
                //<!--
                function UpdateAllChildren(nodes, checked)
                {
                    for (var i=0; i < nodes.get_count(); i++)
                    {
                        var node = nodes.getNode(i);
                        node.set_checked(checked);
                        UpdateAllChildren(node.get_nodes(), checked);       
                    }
                }

                function AfterCheck(treeView, args)
                {
                    var node = args.get_node();
                   
                    if (!node.get_checked() && node.get_parent() != treeView)
                    {
                        node.get_parent().set_checked(false);
                    }
//                    if(node.get_checked())
//                    {
//                        node.get_parent().set_checked(true);
//                    }
        
                    var siblingNodes = node.get_parent().get_nodes();
        
                    var allChecked = true;
                    for (var i = 0; i < siblingNodes.get_count(); i++)
                    {
                        var siblingNode = siblingNodes.getNode(i);
                        if (!siblingNode.get_checked())
                        {
                            allChecked = false;
                            break;
                        }
                    }
                   
                    if (allChecked && node.get_parent() != treeView)
                    {
                        node.get_parent().set_checked(true);
                    }
                   
                    UpdateAllChildren(node.get_nodes(), node.get_checked());
                }
               
                //-->
        </script>

最后么,你可以在WEB.config里面预设文件夹的位置

 <appSettings>
  <add key="ShowCustomErrors" value="false"/>
  <add key="FolderPath" value="c:\test\"/>
  <!-- root path of dst folders -->
  <add key="TemplatePath" value="c:\template\"/>
  <!-- root path of tempaltes -->
   </appSettings>

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 7/3/2008 at 9:27 AM
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed

如何在浏览器里打开本地文件

一个客户一定要实现这个功能,可是自从IE6的SP1后因为安全问题就被锁掉了。到了XP SP2后更是从OS层锁了。网上发现了个解法,当然不够安全。至少能SOLVE问题先 

Symptom Problem opening up local files in a Internet Explorer window. For example, the following code works on some systems and does not work in some. Test Explanation / Wor

  

Symptom

Problem opening up local files in a Internet Explorer window. For example, the following code works on some systems and does not work in some.

<a href="C:\Filename.TXT" target="_blank">Test</a>

Explanation / Workaround: from Eric Shen [MS]

The issue is a new security feature in Internet Explore 6 Service Pack 1. In order to prevent Internet vicious codes from accessing your local files, the development team developed the new security feature and included it in IE6 SP1. Please be advised that this is a normal behavior. Actually, IE6 SP1 includes new security code checks that prevent "zone elevation". This means that documents located in the "Internet" zone will not be granted access (through HREFs, scripting...etc) to documents in the "My Computer" zone. Only documents located in the "Trusted" or "My Computer" zone can access documents in the "My Computer" zone. Therefore, if you want to allow untrusted documents to access documents in the "My Computer" zone, you might add the source URL in "Trusted sites" (this must be done with caution for obvious security reasons). The "Local Intranet" zone is trusted as well.

Furthermore, the following registry key allows disabling the new security codes check that prevent "zone elevation": - You can create this DWORD key and set it zero to disable this new feature. Also, you can enable it by changing it to 1 at any time.

HKCU\Software\Microsoft\Internet Explorer\Main

Disable_Local_Machine_Navigate = 0 (REG_DWORD)

It is not recommended to use above registry key since it breaks the "zone elevation" security fix. Please use this tweak only if you have a valid reason to do so. The above is a per-user setting.

(XP Service Pack 2) Local Machine restrictions prevents even the Trusted sites from opening files in My Computer Zone

In Windows XP Service Pack 2, no site from any Zone can open files in local machine zone, whereas in pre-SP2, only Internet Zone sites were restricted to open local files, while Trusted/Intranet can.

While the above method (Disable_Local_Machine_Navigate) works fine in Windows XP Service Pack 2 also, here is more information and another workaround for this issue:

Security Zone value 2101 corresponds to URLACTION_FEATURE_ ZONE_ELEVATION
Description: Web sites in less privileged Web content zones can navigate into this zone.

"Tweak" or alter the Lockdown Zone template itself:

Disabling this restriction still breaks the "Zone Elevation" security fix. Use only for valid reasons.

Open Registry Editor and navigate to:

[HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lockdown_Zones\0]

Backup the key to a REG file and in the right-pane, set the value 2101 to 0karound: from Eric Shen [MS] The issue is a new security feature in Internet Explore 6 Service Pack 1. In order to prevent Internet vicious codes from accessing your local files, the development team developed the new security feature and included it in IE6 SP1. Please be advised that this is a normal behavior. Actually, IE6 SP1 includes new security code checks that prevent "zone elevation". This means that documents located in the "Internet" zone will not be granted access (through HREFs, scripting...etc) to documents in the "My Computer" zone. Only documents located in the "Trusted" or "My Computer" zone can access documents in the "My Computer" zone. Therefore, if you want to allow untrusted documents to access documents in the "My Computer" zone, you might add the source URL in "Trusted sites" (this must be done with caution for obvious security reasons). The "Local Intranet" zone is trusted as well. Furthermore, the following registry key allows disabling the new security codes check that prevent "zone elevation": - You can create this DWORD key and set it zero to disable this new feature. Also, you can enable it by changing it to 1 at any time. HKCU\Software\Microsoft\Internet Explorer\Main Disable_Local_Machine_Navigate = 0 (REG_DWORD) It is not recommended to use above registry key since it breaks the "zone elevation" security fix. Please use this tweak only if you have a valid reason to do so. The above is a per-user setting. (XP Service Pack 2) Local Machine restrictions prevents even the Trusted sites from opening files in My Computer Zone In Windows XP Service Pack 2, no site from any Zone can open files in local machine zone, whereas in pre-SP2, only Internet Zone sites were restricted to open local files, while Trusted/Intranet can. While the above method (Disable_Local_Machine_Navigate) works fine in Windows XP Service Pack 2 also, here is more information and another workaround for this issue: Security Zone value 2101 corresponds to URLACTION_FEATURE_ ZONE_ELEVATION Description: Web sites in less privileged Web content zones can navigate into this zone. "Tweak" or alter the Lockdown Zone template itself: Disabling this restriction still breaks the "Zone Elevation" security fix. Use only for valid reasons. Open Registry Editor and navigate to: [HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Lockdown_Zones\0] Backup the key to a REG file and in the right-pane, set the value 2101 to 0

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 6/27/2008 at 6:11 PM
Categories: Technologies
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (8) | Post RSSRSS comment feed

坚持和放弃

就像小时候故事书中读到的善于恶一样。在坚持和放弃中长辈们总是教导我们凡事要坚持,绝不能轻易放弃
可孰不知界定轻易一词的定义是何等之难,何等之复杂
长大后常常会在一些事上挣扎
放弃了,前功尽弃,丢掉眼前不说,弄不好还会后悔自责
坚持了,亦要付出几倍的代价去实现,可谓绝对的零“性价比”
比方说日文,比方说吉他,比方说感情
我想自己大体还是遵从坚持为先的原则。。。
在不断地反省斗争中慢慢坚持一些事
但越来越多的事情需要时间,需要策略,需要能够支撑信念的东西
然后才回过头来像小孩子一样,依依不舍的放手一些
这不是我的天性,但我不得不做
上班以后的人际关系和周遭环境与大学大相径庭
而继续在读PART-TIME MASTER的我,等于又一次的嵌在夹缝中
生活在重组的时候总是伴随着痛苦,就像地壳运动后的惨剧一样
不由想到前两天看功夫熊猫的时候乌龟大师说的话,觉得非常有禅理
Yesterday is history
Tomorrow is mystery
but today is a gift
的确,Nothing is accident,无论是选择坚持还是放弃
都会有它的优劣及因果
何不好好把握眼前的每一天
让现在的自己去印证未来的成功呢

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: 304
Posted on: 6/16/2008 at 10:48 PM
Categories: 我的日志
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed