Archive for the ‘c#’ Category

Microsoft Silverlight 4 正式发布

Microsoft Silverlight 4 正式发布!版本号为:4.0.50401.0.为了争夺急速增长的在线视频市场,软件巨人发布了新视频播放器程序:Silverlight.微软的描述是:Silverlight是一个跨浏览器的、跨平台的插件,为Web带来下一代媒体体验和丰富的交互式应用程序体验.Silverlight并不是视频播放器,也不是Youtube的竞争对手,从技术上说它也不是一个新事物.

Silverlight 4 提供一整套强大的功能给商务应用程序开发人员,将最佳的 .NET 平台带入浏览器架构的经验之中.Silverlight 同时针对客户所面对、以及工作人员所面对的应用程序提供了开发和部署现代商务应用程序的理想平台.

商务应用程序开发

Silverlight 4 将自己定位成在 Web 上建立商务应用程序的自然选择:

适用于应用程序开发人员的新功能
•    广泛的打印支持启用了书面报表和文件,以及虚拟打印检视,不论屏幕的内容为何.
•    包含超过 60 个可自定义、可设定样式组件的一整组表单控件.新的控件包括了具有超链接、影像和编辑与屏蔽文本框的 RichTextbox,以进行复杂的字段验证.增强的控件包括了具有可排序/可重设大小的栏和复制/贴上列的 DataGrid.
•    WCF RIA Services 引入企业等级的网络和数据存取,以建立多层式架构 (N-Tier) 应用程序,包括了交易、数据分页、WCF 和 HTTP 增强.
•    本地化的增强,包括了双向文字、由右至左支持和复杂的脚本,例如阿拉伯文、希伯来文和泰文以及 30 种新语言.
•    .NET Common Runtime (CLR) 现在可让同一份编译好的程序代码无须修改地执行于桌面和 Silverlight 上.
•    增强的数据系结支持,包括了透过在系结之中进行数据群组/编辑和字符串格式设定,来增加弹性和产能.
•    受管理的扩充性架构支持建立大型的复合应用程序.
•    独一无二的 Silverlight 工具支持,这是 Visual Studio 2010 中的新功能.包括了可完整编辑的设计接口、拖放式数据系结、自动绑定控件、数据源选择、与 Expression Blend 样式资源整合、Silverlight 项目支持和完整的 IntelliSense.

开发人员工具
•    可绘制控件和配置的可完整编辑的设计接口.
•    丰富的属性方格,和新的数值编辑器.
•    数据系结的拖放支持,以及自动建立绑定控件,例如 listbox、datagrid.新的数据源窗口和选择器.
•    根据建立于 Expression Blend 中的设计人员资源,轻松挑选样式和资源,以建立美观的应用程序.
•    针对 Silverlight 应用程序提供内建的项目支持.
•    具备 XAML 和 C# 和 VB 语言的完整 intellisense 的编辑器.
提供更丰富、更互动的经验
Silverlight 已经是使用中的一个广泛平台,可同时针对应用程序和单纯的媒体案例 (包括了 HD 质量、透过 Smooth Streaming 的互动视讯) 建立丰富的经验.Silverlight 4 提供额外的功能来让您建立更丰富、更吸引人的高效能互动经验和创新的媒体经验:
•    流畅的接口增强可透过动画效果提升应用程序的使用性.
•    网络摄影机和麦克风可让您在聊天或客户服务应用程序等情况中分享视讯和音频.
•    音频和视讯本机录制功能无须服务器互动即可撷取 RAW 视讯,因而启用了众多的用户互动和通讯案例,例如视频会议.
•    以复制和贴上或拖放等功能将数据放到您的应用程序内.
•    长列表现在可以用鼠标滚轮轻松地卷动.
•    透过右键内容菜单等新功能支持传统的桌面互动模型.
•    支持 Google 的 Chrome 浏览器.
•    效能优化意指 Silverlight 4 应用程序可以更快地启动,并且执行速度是相等的 Silverlight 3 应用程序的 200%.
•    多重触控支持可将许多笔势和触控互动整合至使用者经验之中.
•    多播网络可让企业降低串流广播事件的成本,例如公司会议和训练,并且完美地与现有的 Windows Media Server 串流基础结构互通.
•    PlayReady 增强了以 Silverlight DRM 来保护 H.264 媒体的内容.
•    音频/视讯串流的输出保护可让内容拥有者或散发者确保受保护的内容只能经由安全的视讯联机来检视.

超越浏览器
Silverlight 3 率先提供新等级的多样化因特网应用程序 (Rich Internet Applications) 以运作于桌面上,完全不需要额外的程序代码或 Runtime.Silverlight 4 更扩充此功能:
针对沙盒应用程序
•    将 HTML 放在您的应用程序内,以便更紧密地与 Web 服务器的内容整合,例如电子邮件、说明和报表.
•    提供「弹出式」通知窗口的支持,以便让应用程序在用户运作另一个应用程序时,透过任务栏上的弹出窗口,告知状态或变更 信息.
•    脱机 DRM 可让具备 PlayReady 技术的现有 Silverlight DRM 脱机工作.受保护的内容可以透过持续性的授权来提供,如此使用者可以立即脱机,并开始享用其内容.
•    控制 UI 的各个层面,包括了窗口设定,例如开始位置、大小和组件区块.
针对受信任的应用程序
•    读取和写入档案至使用者的 MyDocuments、MyMusic、MyPictures 和 MyVideos 文件夹 (或非窗口平台的对等文件夹),例如储存媒体档案和取得报表的本机副本.
•    执行 Office 等其他桌面程序,例如要求 Outlook 传送电子邮件、传送报表给 Word 或传送数据给 Excel.
•    COM 自动化可透过呼叫应用程序组件来存取装置和其他系统能力;例如存取 USB 安全性卡片阅读机.
•    新的用户接口,可在标准的 Silverlight 沙盒之外要求应用程序权限存取.
•    组策略对象可让组织调整哪些应用程序可拥有提高的信任.
•    在更多样化的信息站和媒体应用程序的全屏幕模式中提供完整的关键词支持.
•    网络的增强允许您在没有安全策略档案下跨网域存取.

下载:Microsoft Silverlight 

Advertisements

Flex IDE for Visual Studio.NET

IIS 7.0添加URL重写模块

 

  1. Go to IIS Manager
  2. Select “Default Web Site”
  3. In the Feature View click “URL Rewrite Module“
  4. In the “Actions” pane on right hand side click on “Add rules…
  5. In the "Add Rules" dialog, select the "Blank Rule" and click "Ok"

Now you must define the actual rewrite rule. In the URL rewrite module, a rewrite rule is defined by specifying four required pieces of information:

  • Name of the rule;
  • Pattern to use for matching the URL string;
  • Optional set of conditions;
  • Action to perform if a pattern is matched and all conditions checks succeed.
Naming a rule

In the “Name” text box enter a name that will uniquely identify the rule, for example: ”Rewrite to article.aspx”.

Defining a pattern

In the “Pattern” text box enter the following string:

^article/([0-9]+)/([_0-9a-z-]+)

This string is a regular expression that specifies that the pattern will match any URL string that meets the following conditions:

  1. Starts with the sequence of characters “article/”.
  2. Contains one or more numeric characters after the first “/”.
  3. Contains one or more alphanumeric or “_” or “-” characters after the second “/”.

Notice that certain parts of the regular expression are within parentheses. These parentheses create capture groups, which can be later referenced in the rule by using back-references.

Defining an action

Since the rule that we are creating is supposed to rewrite the URL, choose the “Rewrite” action type that is listed in the “Action” group box. In the “Rewrite URL:” text box, enter the following string:

article.aspx?id={R:1}&title={R:2}

This string specifies the new value to which the input URL should be rewritten. Notice that for the values of the query string parameters we used {R:1} and {R:2}, which are back-references to the capture groups that were defined in the rule pattern by using parentheses.

Leave default values for all other settings. The "Edit Rule" property page should look like the following page:

Save the rule by clicking on “Apply” action on the right hand side.

Viewing the rewrite rule in configuration file

The rewrite rules are stored either in aplicationHost.config file or in web.config files. To check the configuration of the rule that we have just created, open a web.config file located in %SystemDrive%inetputwwwroot. In this file you should see the <rewrite> section that contains this rule definition:

<rewrite>
  <rules>
    <rule name="Rewrite to article.aspx">
      <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
    </rule>
  </rules>
</rewrite>

Testing the rule

To test that the rule correctly rewrites URL’s, open a Web browser and request the following URL:

http://localhost/article/234/some-title

You should see that the rewrite rule on web server has changed the original URL to article.aspx and it has passed “234” and “some-title” as values for query string parameters.

Creating a redirect rule

Now we will create a redirect rule that will redirect all URLs in the following format:

http://localhost/blog/some-other-title/543
will be redirected to:
http://localhost/article/543/some-other-title

To do this, open the URL Rewrite feature view UI in IIS Manager and then click "Add Rule…" and select "Blank Rule" template again.
Within the “Edit Rule” page, enter the following:

  • Name: "Redirect from blog" (this is a unique name for the rule)
  • Pattern: "^blog/([_0-9a-z-]+)/([0-9]+)" (This pattern will match the URL string that starts with “blog” and captures the second and third segments of the URL into back-references)
  • Action: "Redirect" (The redirect action will cause a redirect response to be sent back to the browser)
  • Redirect URL: "article/{R:2}/{R:1}" (this substitution string will be used as a redirect URL; notice that it uses back-references to preserve and re-arrange the original URL pieces captured during pattern match)

Leave default values for all other settings. The "Edit rule" property page should look like the following page:

save the rule by clicking on “Apply” action on the right hand side.

Testing the rule

To test that the rule redirects requests correctly, open a Web browser and request the following URL:

http://localhost/blog/some-other-title/323

You should see that the browser was redirected to http://localhost/article/323/some-other-title as a result of redirect rule execution and then the request was rewritten in accordance to the rewrite rule that you have created earlier:

Creating an access block rule

The third rule that we will create is used to block all requests made to Web site if those requests do not have the host header set. This type of rule is useful when you want to prevent hacking attempts that are made by issuing HTTP requests against the IP address of the server instead of using the host name.

We will create this rule without using IIS Manager. Open the Web.config file and locate the <rewrite> section. Insert the following rule:

<rule name="Fail bad requests">
      <match url=".*"/>
      <conditions>
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
      </conditions>
      <action type="AbortRequest" />
</rule>

into the <rules> collection, so that it is a first rule in a collection. The <rewrite> section should look like the following code:

<rewrite>
  <rules>
    <rule name="Fail bad requests">
      <match url=".*"/>
      <conditions>
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
      </conditions>
      <action type="AbortRequest" />
    </rule>
    <rule name="Redirect from blog">
      <match url="^blog/([_0-9a-z-]+)/([0-9]+)" />
      <action type="Redirect" url="article/{R:2}/{R:1}" redirectType="Found" />
    </rule>
    <rule name="Rewrite to article.aspx">
      <match url="^article/([0-9]+)/([_0-9a-z-]+)" />
      <action type="Rewrite" url="article.aspx?id={R:1}&amp;title={R:2}" />
    </rule>
  </rules>
</rewrite>

Let’s analyze the rule to understand what it does.

  • <match url=".*"/> – This element says that the rule will match any URL string
  • <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> – This element adds a condition to the rule that retrieves the host header value by reading the server variable HTTP_HOST, matches it against the pattern “localhost” and then negates the result of matching. In other words, the condition verifies that the host header does not match “localhost”.
  • <action type="AbortRequest" /> – this element tells the URL rewrite module to end the HTTP request.
Testing the rule

To test this rule, open a Web browser and make a request to http://127.0.0.1/article/234/some-title. What you should see is a browser that does not receive any response from the server. However, if you request http://localhost/article/234/some-title, then the Web server will respond successfully.

 

相关地址:http://learn.iis.net/page.aspx/461/creating-rewrite-rules-for-the-url-rewrite-module/

微软DRM尝试

最近研究了一下数字版权管理,用的是微软的DRM 7.1,这两天把它改写成了C#的,今天粘出来。不过还是有不少问题,比如,有些视频无法添加数字版权。可能是格式不是完全符合微软的标准吧。

package.asp改写成package.aspx

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 WMRMOBJSLib;

public partial class doPackage : System.Web.UI.Page
{
    private string seed;
    private string siteurl;
    private string owner;
    private string contentserverprivkey;
    private string contentserverpubkey;
    private string regpage;
    private string licurl;
    private string inputfile;
    private string outputfile;
    private string cid;
    private string rid;
    private string kid;
    private string header;

    private string key;

    protected void Page_Load(object sender, EventArgs e)
    {
        initValue();
        readForm();
        doFun();
    }
    private void initValue()
    {
        seed = (String)Application["seed"];
        siteurl = (String)Application["siteurl"];
        owner = (String)Application["ownerid"];
        contentserverprivkey = (String)Application["contentserverprivkey"];
        contentserverpubkey = (String)Application["contentserverpubkey"];
        cid = "500";
    }
    private void readForm()
    {
        inputfile = "C:\sample.wmv";//Request.Form["filepath"];
        rid = Request.Form["RID"];
        if (rid == null || rid == "")
        {
            rid = "0";
        }

        outputfile = "c:\"+Request.Form["newname"]+".wmv";
        regpage = Request.Form["URL"];

        licurl = this.siteurl + "/"+regpage;
    }
    private void doFun()
    {
        try
        {
            //创建一个Header对象
            WMRMOBJSLib.WMRMHeaderClass headObj = new WMRMOBJSLib.WMRMHeaderClass();
            //创建一个key对象
            WMRMOBJSLib.WMRMKeysClass keyObj = new WMRMOBJSLib.WMRMKeysClass();
            //创建项目对象
            WMRMOBJSLib.WMRMProtectClass projectObj = new WMRMOBJSLib.WMRMProtectClass();

            kid = keyObj.GenerateKeyID();
            keyObj.KeyID = kid;
            keyObj.Seed = seed;
            key = keyObj.GenerateKey();

            headObj.KeyID = kid;
            headObj.LicenseAcqURL = licurl;
            headObj.ContentID = cid;

            headObj.set_Attribute("Description","影片限制:" + rid);
            headObj.SetCheckSum(key);

            if (regpage != "simple.aspx")
            {
                headObj.set_Attribute("RID", rid);
            }

            headObj.Sign(contentserverprivkey);

            header = headObj.Header;

            if (outputfile != "")
            {
                projectObj.InputFile = inputfile;
                projectObj.Key = key;
                projectObj.Header = header;
                projectObj.V1KeyID = kid;

                projectObj.ProtectFile(outputfile);

                Response.Write("<a href=’" + outputfile + "’>" + outputfile + "</a>");
            }
        }
        catch (Exception ex)
        {
            string _error = ex.Message;
            Response.Write(_error);
        }
    }
}
simple.asp 改写成simple.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;

public partial class simple : System.Web.UI.Page
{
    public string licresponse;
    public string strLicenseRequested;
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Buffer = true;
        Response.Expires = 0;

        string conpulicKey;
        string seed;

        conpulicKey = (String)Application["contentserverpubkey"];
        seed = (String)Application["seed"];

        string description;
        Boolean silent;
        string delivery_tag;

        description = "";


        silent = true;

        if (Request.Form["nonsilent"] != "")
        {
            silent = false;
        }

        try
        {
            //创建客户端对象
            WMRMOBJSLib.WMRMChallengeClass objChallenge = new WMRMOBJSLib.WMRMChallengeClass();

            //获取客户端信息
           
            strLicenseRequested = Request.Form.Get("challenge");

            objChallenge.Challenge = strLicenseRequested;

            //
            string varClientInfo;
            string varHeader;

            //在Chanllenge对象中设置客户信息
            varClientInfo = objChallenge.ClientInfo;
            //设置在Chanllenge对象的头
            varHeader = objChallenge.Header;

            /*
             *头对象
             */
            WMRMOBJSLib.WMRMHeaderClass objHeader = new WMRMOBJSLib.WMRMHeaderClass();
            string Kid;

            //把header放入到Header对象中以获得key ID 信息
            objHeader.Header = varHeader;

            int blnResult;
            blnResult = objHeader.Verify(conpulicKey);

            //从Header对象中获取key ID
            Kid = objHeader.KeyID;

            string indiVersion;
            indiVersion = "";
            //indiVersion = objHeader.IndividualizedVersion;

            /*
             * Key 对象
             *
             */
            WMRMOBJSLib.WMRMKeysClass objKey = new WMRMOBJSLib.WMRMKeysClass();
            string varKEY;

            //
            objKey.KeyID = Kid;
            objKey.Seed = seed;

            //
            varKEY = objKey.GenerateKey();

            /*
             * 开始设置权限
             */
            WMRMOBJSLib.WMRMRights objRights = new WMRMOBJSLib.WMRMRights();
            string SetV2Rights;

            objRights.MinimumAppSecurity = 500;     //最小的安全级别 http://msdn.microsoft.com/en-us/library/ms986423.aspx
            objRights.AllowPlayOnPC = 1;            //表示允许在PC机上播放
            objRights.AllowBackupRestore = 1;       //这个表示不允许备份许可证
            objRights.AllowBurnToCD = 0;            //表示不允许烧录到CD上
            objRights.AllowSaveStreamProtected = 0; //表示不允许把已打包的流保存到磁盘上
            objRights.AllowTransferToSDMI = 1;      //表示不允许把文件转移到非SDMI设备上
            objRights.AllowTransferToNonSDMI = 0;   //表示不允许把文件转移到非SDMI设备上
            objRights.DisableOnClockRollback = 0;   //当客户端机器时间更改到更早时间时,该证书失效
            objRights.DeleteOnClockRollback = 0;    //当客户端机器时间更改到更早时间时,该证书自动删除
            objRights.Playcount = 2;
            objRights.PMRights = 51;
            objRights.PMAppSecurity = 150;

            SetV2Rights = objRights.GetAllRights(); //获取所有权限设置

           

            /*
             * Generate a license with the License object
             */
            WMRMOBJSLib.WMRMLicGenClass objLicense = new WMRMOBJSLib.WMRMLicGenClass();
            string varLicense;
           
            object varCategory = new object();
            object varVersion = new object();
           
            Response.Write("====");

            objLicense.KeyID = Kid;
            objLicense.SetKey("", varKEY);
            objLicense.Priority = 10;       //设置优先级别,默认为1

            objLicense.set_Attribute("LIECENSESERVER", "<NAME>License Sever</NAME>");
            objLicense.Rights = SetV2Rights;    //设置证书的播放权限
            objLicense.ClientInfo = varClientInfo; //设置关于客户端计算机信息
            objLicense.IndividualizedVersion = indiVersion;
            objLicense.GetClientVersion(ref varCategory, ref varVersion);
            if (varCategory.ToString() != "0" && varCategory.ToString() != "1")//0:Default DRM component on Win32 platform,1:DRM component on Win32 platform with security upgrade
            {
                //return false;
            }
            objLicense.BindToPubKey = conpulicKey;
            varLicense = objLicense.GetLicenseToDeliver();

            delivery_tag = "deliver";
            Response.Write("——");
            /*
             * Response Object
             */
            WMRMOBJSLib.WMRMResponseClass responseObj = new WMRMOBJSLib.WMRMResponseClass();


            responseObj.AddLicense("2.0.0.0", varLicense);

            this.licresponse = responseObj.GetLicenseResponse();
            Response.Write(licresponse);
        }
        catch (Exception ex)
        {
            Response.Write("\n");
            Response.Write(ex.Message);
        }

    }
}

vs发布站点出现Failed to access IIS metabase问题解决

这个问题,重新安装了aspnet_regiis,就好了。
可能原因:
1 两个framework不知道哪个作为主要的。
2 IIS在安装.net Framework的时候不存在。
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>aspnet_regiis.exe -i
Start installing ASP.NET (2.0.50727).
……………………………..
Finished installing ASP.NET (2.0.50727).
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727>aspnet_regiis.exe /lv
1.1.4322.0 Valid C:WINDOWSMicrosoft.NETFrameworkv1.1.4322aspnet_isapi.dll
2.0.50727.0 Valid (Root) C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_isapi.dll