Skip to main content
 首页 » 编程设计

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

2024年02月23日17luoye11

我有一个在 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); 
} 

有什么想法吗?谢谢

请您参考如下方法:

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

之后是什么?在 URL 中被视为 URL 参数,您可以像这样在代码隐藏中访问这些参数:

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