提要:1、我使用ClickOnce部署了一个应用程序,发布时采用允许给应用程序传递URL参数,并在测试窗体中,使用System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.OriginalString方法来获取激活该应用程序的URL地址。该应用程序发布的访问位置为:http://localhost/ckTest/ckTest.application2、我使用一个测试的website,在启动页面中放置了一个按钮,按钮的事件处理如下:     protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("http://localhost/ckTest/ckTest.application?idcard=111");
    }
3、我的website访问的地址为:http://localhost/webTest/Default.aspx 问题来了:通过访问http://localhost/webTest/Default.aspx,点击页面按钮,启动ckTest应用程序,获得的
ApplicationDeployment.CurrentDeployment.ActivationUri.OriginalString为:http://localhost/ckTest/ckTest.application?idcard=111,一切正常,OK。 然后,在Default页面的Load事件中也加入了如下处理代码:    protected void Page_Load(object sender, EventArgs e)
    {
Response.Redirect("http://localhost/ckTest/ckTest.application?idcard=111");
    }
 通过访问http://localhost/webTest/Default.aspx,启动了ckTest应用程序,获得的
ApplicationDeployment.CurrentDeployment.ActivationUri.OriginalString为:http://localhost/webTest/Default.aspx,而不是http://localhost/ckTest/ckTest.application?idcard=111,让我很纳闷。请高手释疑!!!ps:我用的是VS2005,想实现的是,通过一个页面后台获取需要传递的参数,然后传给应用程序使用,不需要通过按钮点击事件,而是自动跳转的方式。

解决方案 »

  1.   

    启用URL参数在解决方案资源管理器中右键点击你的ClickOnce工程,点击属性进入发布选项卡,点击“选项”按钮,在弹出的界面中选中“允许给应用程序传递URL参数”。
    获取参数 
    下一步就是获取url里的参数值,因为ClickOnce应用程序没有HttpContext,所以就不能使用Request.QueryString方法获取参数。 
    然而可以从发布的上下文获取参数。下面的程序可以返回一个类型为NameValueCollection的url参数集合对象。 using System.Deployment.Application; 
    using System.Web; 
    using System.Collections.Specialized; private NameValueCollection GetQueryStringParameters() 

           NameValueCollection col = new NameValueCollection(); 
           if (ApplicationDeployment.IsNetworkDeployed) 
           { 
                 string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query; 
                 col = HttpUtility.ParseQueryString(queryString); 
           } 
           return col; 
    }希望能帮到你!