xml - treat AbsoluteUri C# -


i'm trying figure out best way treat url mvc project.

as see i'm reading xml file distinguish witch client goes iis.

my problem is, empty url, clients gets redirect wrong path. i'm using node.value.contains(clienturl) , .firstordefault(). whenever happens need adapt xml adding /login# etc.. url's kind similar treat url/path each client use node.value.equals(clienturl) instead.

thanks all.

controller

    public actionresult index(string returnurl)     {         try         {             response.clearcontent();             response.clearheaders();             response.cache.setexpires(datetime.utcnow.addminutes(-1));             response.cache.setcacheability(httpcacheability.nocache);             response.cache.setnostore();                             var useragent = request.useragent;             string urldocliente = request.url.absoluteuri;             sysconfig _sysconfig = new sysconfig(clienturl);             var isandroid = false;             int id = syscoopwebconfig.empresa;             if (useragent != null)             {                 if (useragent.tolower().contains("android".tolower()))                 {                     isandroid = true;                 }                 else                 {                     isandroid = request.browser.ismobiledevice;                 }             }              if (isandroid)             {                 string url = syswebconfig.urlappmobile;                 if (url != "")                 {                     return redirect(url);                 }             }              if (!request.isauthenticated)             {                 session["sesparam"] = null;                 return redirect(syswebconfig.urlappdesktop + "/login#");             }         }         catch (exception e)         {             viewbag.message = e.message.tostring() + ". url wsdl: " + syswebconfig.wsdl;         }          return view();     } 

reading xml

    private static void readxmlconfig(string clienturl)     {         try         {              xmldocument docx = new xmldocument();              string syswebpath = appdomain.currentdomain.basedirectory;              docx.load(webpath + "/syswebconfig.xml");              xelement xml = docx.toxelement();             var config   = (from nodes in xml.descendants("client")                               node in nodes.attributes("url")                               node.value.contains(clienturl)                                select nodes).firstordefault();              if (config != null)             {                 _client = int.parse(config.element("clientid").value);                 _wsdl = config.element("wsdl").value;                 _urlappmobile = config.element("urlappmobile").value;                 _urlappdesktop = config.element("urlappdesktop").value;             }          }         catch (exception)         {             throw new exception('error reading xml file');         }     } 

xml sample

    <?xml version="1.0" encoding="utf-8"?>     <clientconfig>       <sysweb>        <client url="http://192.168.2.31/sysweb/client1">             <wsdl>http://192.168.2.25/wssysweb/sysweb.dll/soap/isysweb</wsdl>             <clientid>001</clientid>             <urlappmobile>http://192.168.2.31/syswebmobile/appclient1</urlappmobile>             <urlappdesktop>http://192.168.2.31/sysweb/appclient1</urlappdesktop>         </client>        <client url="http://192.168.2.31/sysweb/client1/login#">             <wsdl>http://192.168.2.25/wssysweb/sysweb.dll/soap/isysweb</wsdl>             <clientid>001</clientid>             <urlappmobile>http://192.168.2.31/syswebmobile/appclient1</urlappmobile>             <urlappdesktop>http://192.168.2.31/sysweb/appclient1</urlappdesktop>         </client>                <client url="http://192.168.2.31/sysweb/client2">             <wsdl>http://192.168.2.25/wssyweb/syspweb.dll/soap/isysweb</wsdl>             <clientid>002</clientid>             <urlappmobile>http://192.168.2.31/syswebmobile/appclient2</urlappmobile>             <urlappdesktop>http://192.168.2.31/sysweb/appclient2</urlappdesktop>         </client>                <client url="http://192.168.2.31/sysweb/client3">             <wsdl>http://192.168.2.25/wssyweb/syspweb.dll/soap/isysweb</wsdl>             <clientid>003</clientid>             <urlappmobile>http://192.168.2.31/syswebmobile/appclient3</urlappmobile>             <urlappdesktop>http://192.168.2.31/sysweb/appclient3</urlappdesktop>         </client>              </sysweb>     </clientconfig> 

i´ve decided go simple using array set them same.

           string clienturl = request.url.absoluteuri;                             string[] vurlarray = clienturl.split('/');              if (vurlarray.count() >= 6)             {                 clienturl = "";                 (int = 0; <= 4; i++)                 {                     clienturl = clienturl + vurlarray[i] + "/";                  }                 clienturl = clienturl.substring(0, urldocliente.lastindexof("/"));                           }      

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -