2013-10-24 24 views
-3

使用ASP.Net(在C#中),我需要生成一個包含人名,地址等的標記。我幾乎沒有任何有關ASP.NET(或.NET語言)的經驗,我得到這份任務。請有人請指導我糾正路徑嗎?如何從輸入字段生成<a>標記

鏈接應該是這樣的:需要

https://example.com/PRR/Info/Login.aspx?SupplierId=36&RegisteredUserLogin=T000001&Mode=RegisteredLoginless&RegisteredModeFunction=AutoShowTotals&RegisteredModeFunction=AutoShowTotals&PayerCountry=FI&[email protected]&ExternalOrderId=1000123&ServiceId=286&Amount286=5000.00&PayerInfo286=T000001|10000123|type1|m&SuccessReturnURL=http://success.html&FailureReturnURL=http://failure.html&SuccessCallbackURL=http://youpay.com/p247/success.html&FailureCallbackURL=http://yourfailure.html

以下組件/字段被髮送到API,以便用戶預先填充的信息: 名字, 姓氏, 供應商id =整數, 人的用戶登陸(應由1。實施例遞增:人1 = T00001 PERSON2 = t00002等), PayerCountry, 電子郵件, 量

由於某種原因,我的管理層認爲這是非技術人員可以做的事!任何幫助,將不勝感激!

謝謝!

+1

這是一個有趣的網址。 –

+1

「我需要生成一個HTML鏈接」是什麼意思?你的意思是,你需要輸入字段併爲你的頁面生成一個''標籤? – McGarnagle

+3

愚蠢的事情,但如果你是一個非技術人員,你可能會考慮改變你的用戶名爲「notaprogrammer」... – NotMe

回答

1

我喜歡爲這種大規模字符串構造首先建立一個數據結構。在這種情況下,一本字典的工作原理:

string CreateUrl(string firstName, string lastName, int supplierID, int login, string payerCountry, string email, decimal amount) 
{ 
    int personId = 0; 
    var query = new Dictionary<string, string> 
    { 
     { "SupplierId",    "36" }, 
     { "RegisteredUserLogin",  "T" + login.ToString().PadLeft(5, '0') }, 
     { "Mode",     "RegisteredLoginLess" }, 
     { "RegisteredModeFunction", "AutoShowTotals" }, 
     { "PayerCountry",   payerCountry }, 
     { "ForcePayerEmail",   email }, 

     // etc ... 

     { "FailureCallbackURL", "http://yourfailure.html" }, 
    }; 

    string baseUrl = "https://example.com/PRR/Info/Login.aspx?"; 

    // construct the query string: 
    // join the key-value pairs with "=" and concatenate them with "&" 
    // URL-encode the values 
    string qstring = string.Join("&", 
     query.Select(kvp => 
      string.Format("{0}={1}", kvp.Key, HttpServerUtility.UrlEncode(kvp.Value.ToString())) 
     ) 
    ); 

    return baseUrl + qstring 
} 

(注意查詢字符串值必須是URL編碼,以確保它們不會與預留的網址字符,如「&」衝突)

現在你可以構造URL在您的ASPX頁面:

<script runat="server"> 
    public string URL 
    { 
     get 
     { 
      // TODO insert the user's fields here 
      return CreateUrl(FirstName, LastName, ...); 
     } 
    } 
</script> 

<a href='<%= URL %>'>Login</a> 

另外一個音符 - 這聽起來像你想構建新用戶自動增量ID。這是使用數據庫最容易做到的(數據庫可以比Web服務器更容易地處理併發和持久性)。我建議將一個記錄插入帶有自動增量字段的表格中,並使用數據庫生成的值作爲ID。