2013-10-24 26 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。