ASP.net 4.0 c# 中的可选参数

发布于 2024-12-08 17:04:10 字数 2020 浏览 1 评论 0原文

我有一个用 ASP.NET 4.0 构建的网站,目前有一个包含 URL 的下拉框、一个转到该 URL 并解析文本的按钮,最后是一个包含解析文本的结果框。

我想要做的是,我不想访问我的网站并在下拉框中选择 URL,而是希望将参数作为完整 URL 传递,然后让按钮转到该网站,然后执行其操作。有点像我可以交给用户的永久链接

例如:

http://localhost:62554/WebSite5 /Default.aspx --> http://google.com

google.com 被放入一个变量中(假设它的 MyURL )并且按钮就像在下拉框中一样接受它。 处收到错误 500

using (StreamReader objReader = new StreamReader(objRequest.GetResponse().GetResponseStream()))

string newURL;
String url;

protected void Page_Load(object sender, EventArgs e)
{

    //Request.Params.Get("newURL").ToString();
    //string url = Request["newURL"];
    //url = Request.QueryString["newURL"].ToString();
    url = Request.QueryString["newURL"].ToString();

    parseButton_Click(sender, e);
}
protected void parseButton_Click(object sender, EventArgs e)
{

    //MyURL = deviceCombo.Text;
    //MyURL = Request.Params.Get("");
    //MyURL = Request.Params.Get("newURL");
    //MyURL = newURL;
    //string MyURL = Request.Params["newURL"].ToString();

    WebRequest objRequest = HttpWebRequest.Create(url);
    objRequest.Credentials = CredentialCache.DefaultCredentials;
    using (StreamReader objReader = new StreamReader(objRequest.GetResponse().GetResponseStream()))
    {
        originalText.Text = objReader.ReadToEnd();
    }

    //Read all lines of file
    String[] crString = { "<BR>&nbsp;" };
    String[] aLines = originalText.Text.Split(crString, StringSplitOptions.RemoveEmptyEntries);
    String noHtml = String.Empty;

    for (int x = 0; x < aLines.Length; x++)
    {
        if (aLines[x].Contains(filterCombo.SelectedValue))
        {
            noHtml += (RemoveHTML(aLines[x]) + "\r\n");

        }
    }

    //Print results to textbox
    resultsBox.Text = String.Join(Environment.NewLine, noHtml);
}

**更新的代码:现在在Any ideas? ?谢谢

I have a website built in ASP.NET 4.0 and currently I have a drop down box with URLs, a button that goes to that URL and parses out text and then finally a results box with the parsed text.

What I want to do is instead of going to my website and choosing the URL in the drop down box, I want to pass on the parameter as a full URL and have the button go to that and then do its thing. Kind of like a permanent link that I can hand to a user

For instance:

http://localhost:62554/WebSite5/Default.aspx --> http://google.com

google.com gets put into a variable (lets say its MyURL) and the button takes it just like if it were in the drop down box.
**Updated code: Now getting a error 500 at

using (StreamReader objReader = new StreamReader(objRequest.GetResponse().GetResponseStream()))

string newURL;
String url;

protected void Page_Load(object sender, EventArgs e)
{

    //Request.Params.Get("newURL").ToString();
    //string url = Request["newURL"];
    //url = Request.QueryString["newURL"].ToString();
    url = Request.QueryString["newURL"].ToString();

    parseButton_Click(sender, e);
}
protected void parseButton_Click(object sender, EventArgs e)
{

    //MyURL = deviceCombo.Text;
    //MyURL = Request.Params.Get("");
    //MyURL = Request.Params.Get("newURL");
    //MyURL = newURL;
    //string MyURL = Request.Params["newURL"].ToString();

    WebRequest objRequest = HttpWebRequest.Create(url);
    objRequest.Credentials = CredentialCache.DefaultCredentials;
    using (StreamReader objReader = new StreamReader(objRequest.GetResponse().GetResponseStream()))
    {
        originalText.Text = objReader.ReadToEnd();
    }

    //Read all lines of file
    String[] crString = { "<BR> " };
    String[] aLines = originalText.Text.Split(crString, StringSplitOptions.RemoveEmptyEntries);
    String noHtml = String.Empty;

    for (int x = 0; x < aLines.Length; x++)
    {
        if (aLines[x].Contains(filterCombo.SelectedValue))
        {
            noHtml += (RemoveHTML(aLines[x]) + "\r\n");

        }
    }

    //Print results to textbox
    resultsBox.Text = String.Join(Environment.NewLine, noHtml);
}

Any ideas? Thank you

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

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

发布评论

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

评论(2

み青杉依旧 2024-12-15 17:04:10

你的问题很难理解,但我认为你想要做的就是在 URL 中传递网站字符串。我认为你想要做的是使用 URL 参数,所以如果他们转到“http://localhost:62554/Website5/default.aspx?newURL=http://google.com”,就好像他们选择了 google .com 在下拉列表中。

之后还有什么吗? URL 中的内容被视为 URL 参数,您可以在代码隐藏中访问这些参数,如下所示:

string newURL = Request.Params.Get("newURL");

Your question was hard to understand, but I think what you are trying to do is pass in the website string in the URL. I think what you want to do is use URL params, so if they go to "http://localhost:62554/Website5/default.aspx?newURL=http://google.com" it acts as if they had chosen google.com in the dropdown.

Anything after the ? in the URL is treated as an URL param, you can access these params in the codebehind like this:

string newURL = Request.Params.Get("newURL");
不必在意 2024-12-15 17:04:10

您可以从 Request 对象获取 URL 变量。

string url = Request["newURL"];

将其放在您喜欢的任何地方,例如 Page_Load

protected void Page_Load(object sender, EventArgs e)
{
    string url = Request["newURL"];
}

You can get the URL variable from the Request object.

string url = Request["newURL"];

Put this wherever you like such as Page_Load

protected void Page_Load(object sender, EventArgs e)
{
    string url = Request["newURL"];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文