uploadify 将查询传递给通用处理程序

发布于 2024-11-29 08:02:11 字数 1997 浏览 0 评论 0原文

在这部分停留了几天,我仍然无法将任何查询字符串传递给通用处理程序。

我的代码如下:

1st:查询字符串被传递到Upload.aspx。我在页面加载部分检索它:

My Upload.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {

        int userId = Convert.ToInt32(Request.QueryString["userid"]);
        int upload = Convert.ToInt32(Request.QueryString["upload"]);
        int childId = Convert.ToInt32(Request.QueryString["childid"]);
    }

My Upload.aspx

<script type="text/javascript">
   // <![CDATA[
   $(document).ready(function() {
   $('#fileInput').uploadify({
   'uploader': 'uploadify/uploadify.swf',
   'script': 'Upload.ashx',
   'cancelImg': 'uploadify/cancel.png',
   'auto': true,
   'multi': true,
   'fileDesc': 'Image Files',
   'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
   'queueSizeLimit': 90,
   'sizeLimit': 4000000,
   'buttonText': 'Choose Images',
   'folder': '/uploads',
   'onAllComplete': function(event, queueID, fileObj, response, data) {

   }
 });

});

我的 upload.ashx

public void ProcessRequest(HttpContext context)
    {

        try
        {
            HttpPostedFile file = context.Request.Files["Filedata"];
            Global.myDBManager.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            Global.myDBManager.DataProviderType = DBMgr.DataProvider.MySql;
            Global.myDBManager.Connect();
            int id = 1 + Convert.ToInt32(Global.myDBManager.ExecuteScalar("Select id from picture order by picture_id desc limit 1"));
            Global.myDBManager.ExecuteScalar("Insert into image(picture_id,user_id) VALUE('" + id + "', '" + userId + "')");
            file.SaveAs("C:\\" + id.ToString() + file.FileName);
            context.Response.Write("1");
        }
        catch (Exception ex)
        {
            context.Response.Write("0");
        }
}

如何将查询传递到 upload.ashx?其中 userId 是我试图传递的查询。

提前致谢 !

Been stuck at this part for a few days that i still could not pass any query string to generic handler.

my code is as follows:

1st: query string is passed into Upload.aspx. and i retrieve it in the page load section:

My Upload.aspx.cs

protected void Page_Load(object sender, EventArgs e)
    {

        int userId = Convert.ToInt32(Request.QueryString["userid"]);
        int upload = Convert.ToInt32(Request.QueryString["upload"]);
        int childId = Convert.ToInt32(Request.QueryString["childid"]);
    }

My Upload.aspx

<script type="text/javascript">
   // <![CDATA[
   $(document).ready(function() {
   $('#fileInput').uploadify({
   'uploader': 'uploadify/uploadify.swf',
   'script': 'Upload.ashx',
   'cancelImg': 'uploadify/cancel.png',
   'auto': true,
   'multi': true,
   'fileDesc': 'Image Files',
   'fileExt': '*.jpg;*.png;*.gif;*.bmp;*.jpeg',
   'queueSizeLimit': 90,
   'sizeLimit': 4000000,
   'buttonText': 'Choose Images',
   'folder': '/uploads',
   'onAllComplete': function(event, queueID, fileObj, response, data) {

   }
 });

});

My upload.ashx

public void ProcessRequest(HttpContext context)
    {

        try
        {
            HttpPostedFile file = context.Request.Files["Filedata"];
            Global.myDBManager.ConnectionString = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
            Global.myDBManager.DataProviderType = DBMgr.DataProvider.MySql;
            Global.myDBManager.Connect();
            int id = 1 + Convert.ToInt32(Global.myDBManager.ExecuteScalar("Select id from picture order by picture_id desc limit 1"));
            Global.myDBManager.ExecuteScalar("Insert into image(picture_id,user_id) VALUE('" + id + "', '" + userId + "')");
            file.SaveAs("C:\\" + id.ToString() + file.FileName);
            context.Response.Write("1");
        }
        catch (Exception ex)
        {
            context.Response.Write("0");
        }
}

how do i pass the query into upload.ashx? where userId is the query that im trying to pass.

thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝情姑娘 2024-12-06 08:02:11

在 ProcessRequest 方法中使用它。您可以使用 Context.Request 来获取查询字符串参数。

int userId = Convert.ToInt32(Context.Request.QueryString["userid"]);

确保您已在应用程序 web.config 中完成 url 映射。

例如,

<system.web>
    <urlMappings enabled="true">
    <add url="~/Upload.aspx" mappedUrl="~/Upload.ashx"/>
    </urlMappings>
    ...

这个链接可能会给您一些关于编写通用处理程序的想法。

Use this in ProcessRequest method. You can use Context.Request to get the querystring parameters.

int userId = Convert.ToInt32(Context.Request.QueryString["userid"]);

Make sure you have done url mapping in your application web.config.

E.g.

<system.web>
    <urlMappings enabled="true">
    <add url="~/Upload.aspx" mappedUrl="~/Upload.ashx"/>
    </urlMappings>
    ...

This link might give you some idea on writing generic handlers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文