Previous to the partner QR code when the hidden URL is too long, causing the partner to ask for printing at the time of the problem, the URL length of 50 bytes, so write a shortened URL function.
varURL =string. Format ("{0}/billing/scancode? TENANTID={1}&BUSSINESSTYPE={2}&GROUPNUMBER={3}&DEVICEID={4}", BaseUrl, args. TenantId, (int) bussinesstype.synctransaction, Groupnumber, device. ID);//long URLs optimized to short URLsvarCreatshoturl =string. Format ("/billing/scancode? TENANTID={0}&BUSSINESSTYPE={1}&GROUPNUMBER={2}&DEVICEID={3}", args. TenantId, (int) bussinesstype.synctransaction, Groupnumber, device. ID);varInvoiceurlrepository = RF. Concrete<invoiceurlrepository>(); Invoiceurl model=NewInvoiceurl ();stringid = commonshorturl.getshorturl (creatshoturl,0); URL= BaseUrl +"/t?e="+ ID;
Add a second controller
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;usingRafy.domain;namespaceDBI. saas.web.controllers{ Public classTcontroller:controller {//Get:invoiceurl /// <summary> ///get the real URL based on the key of the short URL and jump/// </summary> /// <param name= "Urlkey" >key for short URL</param> /// <returns></returns>[Route ("c/{e:maxlength ()}")] PublicActionResult Index (stringe) {if(!string. IsNullOrEmpty (e)) {LongID =Commonshorturl.unshort (e); varInvoiceurlrepository = RF. Concrete<invoiceurlrepository>(); //Enquiry varQ =NewCommonquerycriteria (); varModel =Invoiceurlrepository.getbyid (ID); if(model = =NULL) { returnContent ("non-existent url! "); } returnRedirect (model. Urlvalue); } Else { returnContent ("parameter Error! "); } } }}
Shortening the URL controller code
usingRafy.domain;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespaceDBI. saas.web.controllers{ Public classCommonshorturl {Static stringNumber ="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; /// ///Compression ID Identification/// /// /// Public Static stringShort (LongN) {stringresult =string. Empty; intL =number.length; while(n/l >=1) {result= number[(int) (n% l)] +result; N/=l; } result= number[(int) n] +result; returnresult; } /// ///Restore ID Identification/// /// /// Public Static LongUnshort (strings) {Longresult =0; S=S.trim (); intL =s.length; intm =number.length; for(intx =0; x < L; X + +) {result+ = Number.indexof (S[l-1-X]) * (Long) Math.pow (m, x); } returnresult; } /// <summary> ///Simplify URLs/// </summary> /// <param name= "Paramurl" ></param> /// <returns></returns> Public Static stringGetshorturl (stringParamurl,intUrltype) { //long URLs optimized to short URLs varInvoiceurlrepository = RF. Concrete<invoiceurlrepository>(); Invoiceurl Insertmodel=NewInvoiceurl (); Insertmodel.urlvalue=Paramurl; Insertmodel.urltype=Urltype; Invoiceurlrepository.save (Insertmodel); returnCommonshorturl.short (insertmodel.id); } }}
This shortened URL address: http://www.***.com/t?e=***
Shorten url-url short Address link