随笔-4  评论-49  文章-0  trackbacks-2
  2007年9月12日
     摘要: 考虑到此问题的发生很难解决和解决方法的示例意义,特发在首页。

问题提出:Silverlight在IE中无法显示并提示下载,在Firefox中正常
系统环境:Vista, IE7
对应版本:1.0 RC, 1.0 RTW, 1.1 Alpha Aug./Sep. Refresh
现象描述:访问包含Silverlight的页面,提示下载并安装Silverlight,安装后显示安装成功,刷新页面后,仍然提示需要下载安装;然而打开Firefox访问该页面却能够正常显示。注:在Vista中安装要使用Administrator权限(快捷菜单,Run as administrator)
解决过程:
尝试了卸载重新安装,重新启动等,均不能解决。问题看似很简单,但是解决起来却有些无从下手。首先想到的是能否得到一些Log或者Debug的信息,但是没有找到方法;后参考了部分资料,采用如下方法(以后许多问题可以这样查看):  阅读全文
posted @ 2007-09-12 23:30 Ariel Y. 阅读(2265) | 评论 (4)编辑
  2006年1月16日
Web开发做得多了,总觉得是体力活,于是搞些代码让自己脱离无聊的Coding吧(是脱离“无聊的”Coding,不是脱离无聊的“Coding”)。
 

初级阶段

为每个QueryString写转换的代码,针对不同的类型,进行转换和错误处理。
 

中级阶段

写了一个函数,专门做转换(1.1里写的):

  /// <summary>
  
/// Convert query string to parameter.
  
/// </summary>
  
/// <param name="name">Name of query string</param>
  
/// <param name="defaultValue">Default value of query string</param>
  
/// <param name="isRequired">If the query string is required</param>
  private object ConvertParameter(string name, object defaultValue, bool isRequired)

高级阶段

昨天写的,第一次发文,大家拍砖吧:
 
主要是用了Attribute和反射的思想,首先给变量设置HttpQueryString的属性,绑定上相应的QueryString,然后由Page基类来读取相应的QueryString信息。

属性这么写(HttpQueryStringAttribute.cs):

using System;

namespace GooKuu.Framework.Web
{

    
/// <summary>
    
/// Specifies a field for a query string. 
    
/// </summary>
    [AttributeUsage(AttributeTargets.Field)]
    
public sealed class HttpQueryStringAttribute : Attribute
    {
        
private string _name;
        
private object _defaultValue;
        
private bool _isRequired;

        
/// <summary>
        
/// Constructor. The query string must be provided.
        
/// </summary>
        
/// <param name="name">Name of the query string</param>
        public HttpQueryStringAttribute(string name)
        {
            _name 
= name;
            _defaultValue 
= null;
            _isRequired 
= true;
        }

        
/// <summary>
        
/// Constructor. If the query string is not be provided, using the default value.
        
/// </summary>
        
/// <param name="name">Name of the query string</param>
        
/// <param name="defaultValue">Default value of the query string which is not provided</param>
        public HttpQueryStringAttribute(string name, object defaultValue)
        {
            _name 
= name;
            _defaultValue 
= defaultValue;
            _isRequired 
= false;
        }

        
/// <summary>
        
/// Name of the query string.
        
/// </summary>
        public string Name
        {
            
get { return _name; }
        }

        
/// <summary>
        
/// Default value of the query string which is not provided.
        
/// </summary>
        public object DefaultValue
        {
            
get { return _defaultValue; }
        }

        
/// <summary>
        
/// Indicates if the query string must be provided.
        
/// </summary>
        public bool IsRequired
        {
            
get { return _isRequired; }
        }
    }
}

页面基类是这样的(PageBase.cs):

using System;
using System.Reflection;
using System.Web;
using System.Web.UI;

namespace GooKuu.Framework.Web
{
    
/// <summary>
    
/// Base class of all pages.
    
/// </summary>
    public class PageBase : Page
    {
        
/// <summary>
        
/// Override OnLoad method of base class.
        
/// </summary>
        
/// <param name="e"></param>
        protected override void OnLoad(System.EventArgs e)
        {
            ParameterInitialize();
            
base.OnLoad(e);
        }

        
/// <summary>
        
/// Initialize parameters according to query strings.
        
/// </summary>
        private void ParameterInitialize()
        {
            
// Get Type of current page class.
            Type type = this.GetType();

            
// Get all fields of current page class.
            FieldInfo[] fields = type.GetFields();

            
foreach (FieldInfo field in fields)
            {
                
// Get HttpQueryStringAttribute of current field.
                HttpQueryStringAttribute attribute = (HttpQueryStringAttribute)Attribute.GetCustomAttribute(field, typeof(HttpQueryStringAttribute));

                
// If has HttpQueryStringAttribute, this field is for a query string.
                if (attribute != null)
                {
                    SetField(field, attribute);
                }
            }
        }

        
/// <summary>
        
/// Set field according to the HttpQueryStringAttribute.
        
/// </summary>
        
/// <param name="field">The field will be set</param>
        
/// <param name="attribute">The attribute of current field</param>
        private void SetField(FieldInfo field, HttpQueryStringAttribute attribute)
        {
            
// The query string must be provided.
            if (attribute.IsRequired)
            {
                
if (Request.QueryString[attribute.Name] != null)
                {
                    SetFieldValue(field, 
this, attribute.Name, field.FieldType);
                }
                
else
                {
                    
throw new Exception(string.Format("Query string \"{0}\" is required", attribute.Name), new NullReferenceException());
                }
            }
            
// If the query string is not be provided, using the default value.
            else
            {
                
if (attribute.DefaultValue == null || field.FieldType == attribute.DefaultValue.GetType())
                {
                    
if (Request.QueryString[attribute.Name] == null || Request.QueryString[attribute.Name] == string.Empty)
                    {
                        field.SetValue(
this, attribute.DefaultValue);
                    }
                    
else
                    {
                        SetFieldValue(field, 
this, attribute.Name, field.FieldType);
                    }
                }
                
else
                {
                    
throw new Exception(string.Format("Invalid default value of query string \"{0}\"({1})", attribute.Name, field.Name), new NullReferenceException());
                }
            }
        }

        
/// <summary>
        
/// Set the value of current field according to the query string.
        
/// </summary>
        
/// <param name="field">The field will be set</param>
        
/// <param name="obj">The object whose field value will be set</param>
        
/// <param name="name">The name of query string</param>
        
/// <param name="conversionType">The type to be converted</param>
        private void SetFieldValue(FieldInfo field, object obj, string name, Type conversionType)
        {
            
try
            {
                
// Set field value.
                field.SetValue(obj, Convert.ChangeType(Request.QueryString[name], conversionType));
            }
            
catch (Exception ex)
            {
                
throw new Exception(string.Format("The given value of query string \"{0}\" can not be convert to {1}", name, conversionType), ex);
            }
        }
    }
}

在页面里,这样写就OK了(Default.aspx.cs):

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using GooKuu.Framework.Web;

public partial class _Default : PageBase
{
    
    
/// <summary>
    
/// Name 是Query String的名字,"Anonymous"是缺省值。
    
/// 如果没有提供这个Query String,就采用缺省值。
    
/// </summary>
    [HttpQueryString("Name""Anonymous")]
    
public string name;

    
/// <summary>
    
/// UserId 是Query String的名字,不提供缺省值。
    
/// 如果没有提供这个Query String或者提供的格式不正确导致转换失败,都会抛出异常。
    
/// </summary>
    [HttpQueryString("UserId")]
    
public int userId;

    
protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(
string.Format("Name is {0}<br/>", name));
        Response.Write(
string.Format("UserId is {0}<br/>", userId));
    }
}

posted @ 2006-01-16 11:01 Ariel Y. 阅读(4318) | 评论 (26)编辑

问题提出:

随着.net 2.0的发布,我们面临着ASP .NET 1.1到ASP .NET 2.0迁移的任务,中间会遇到好多两个版本的网站在一个服务器上并存的问题。

在IIS 5上,好像一切正常(没有具体研究过)。但是在IIS 6上因为引入了Application Pool的概念,所以会有一些问题。当我们针对不同两个.net版本的网站应用同一个Application Pool的时候,就会出现如下应用程序日志错误(这里ASP.NET 2.0是英文版,ASP.NET 1.1是中文版):

事件类型: 错误
事件来源: ASP.NET 2.0.50727.0
事件种类: 无
事件 ID: 1062
日期:  2006-1-5
事件:  10:04:15
用户:  N/A
计算机: xxxxxxxxxx
描述:
It is not possible to run two different versions of ASP.NET in the same IIS process. Please use the IIS Administration Tool to reconfigure your server to run the application in a separate process.

有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。


事件类型: 错误
事件来源: ASP.NET 1.1.4322.0
事件种类: 无
事件 ID: 1062
日期:  2006-1-5
事件:  10:35:47
用户:  N/A
计算机: xxxxxxxx
描述:
在同一 IIS 进程中不可能运行两个不同的 ASP.NET 版本。请使用 IIS 管理工具重新配置服务器以在一个单独的进程中运行应用程序。

有关更多信息,请参阅在 http://go.microsoft.com/fwlink/events.asp 的帮助和支持中心。

解决方案:

针对不同版本的站点(包括虚拟目录,因为它也要用Application Pool),采用不同的Application Pool。就这么简单。

posted @ 2006-01-16 10:20 Ariel Y. 阅读(1115) | 评论 (2)编辑
  2005年1月28日
Windows XP Theme去年买了这个T628,回来后自己做了个主题文件,放到这里,有小T的朋友可以下载下来玩儿玩儿。用红外线或数据线或者蓝牙传到小T上去就可以了。
下载下来的是一个Zip文件,解开后是一个扩展名为.thm的文件。
用UltraEdit打开看了看,原来里边放的就是一个XML文件加上所有的图片。用XML来描述各个界面的字体颜色和图片名称。
另外有个辅助的工具可以用,这里介绍一下:
Sony Ericsson Themes Creator 1.60
注:这里是Sony Ericsson Developer World Home,需要注册,当然其他地方都有下载,这里是“官方”而已。

如果哪位朋友也是小T的爱好者,欢迎交流,我这里有好多资源哦。
下载地址:T628 Windows XP Theme
posted @ 2005-01-28 16:46 Ariel Y. 阅读(6557) | 评论 (16)编辑