C# - QR code link in case of load balancer












2















I am completely new in this part - I have a QR code on my screen which works for both windows and mobile i.e. you can click on that QR code to open a new window with given page in same browser on window or you can scan the QR code which will open that page in your mobile phone.



previously we have single server it was working fine. We were generating the URL for that QR code as follows -



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

return urlBuilder.ToString();


This used to return the url as "http://site.internal/Controller/Action"



This was working for both desktop & mobile



Now we have deployed app on multiple servers and got the load balancer.



Now URL of the application has changes -



E.G. Load Balanced External URL = https://secure.abc.com



Now when we generate an URL for QR code using same code then it takes the server URL i.e it points to server URL (http://site.internal/Controller/Action) instead of Relative path/current URL.



Is there a way to solve this issue? to take relative path instead of server path?





Edit - I tried changing the code as



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

var cleanUrl = urlBuilder.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Scheme & ~UriComponents.Host & ~UriComponents.Port,
UriFormat.UriEscaped);

return cleanUrl.ToString();


But it works only on Desktop. It does not work on mobile phone as there no URL present on phone when we scan the QR code










share|improve this question























  • Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

    – Fildor
    Nov 16 '18 at 9:44











  • I am dynamically creating a QR code

    – omkar patade
    Nov 16 '18 at 9:49











  • Can you confirm that QR creation methods use the correct uri?

    – Fildor
    Nov 16 '18 at 9:58






  • 1





    I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

    – DavidG
    Nov 16 '18 at 10:05








  • 1





    You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

    – Sergiu Muresan
    Nov 16 '18 at 14:19
















2















I am completely new in this part - I have a QR code on my screen which works for both windows and mobile i.e. you can click on that QR code to open a new window with given page in same browser on window or you can scan the QR code which will open that page in your mobile phone.



previously we have single server it was working fine. We were generating the URL for that QR code as follows -



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

return urlBuilder.ToString();


This used to return the url as "http://site.internal/Controller/Action"



This was working for both desktop & mobile



Now we have deployed app on multiple servers and got the load balancer.



Now URL of the application has changes -



E.G. Load Balanced External URL = https://secure.abc.com



Now when we generate an URL for QR code using same code then it takes the server URL i.e it points to server URL (http://site.internal/Controller/Action) instead of Relative path/current URL.



Is there a way to solve this issue? to take relative path instead of server path?





Edit - I tried changing the code as



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

var cleanUrl = urlBuilder.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Scheme & ~UriComponents.Host & ~UriComponents.Port,
UriFormat.UriEscaped);

return cleanUrl.ToString();


But it works only on Desktop. It does not work on mobile phone as there no URL present on phone when we scan the QR code










share|improve this question























  • Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

    – Fildor
    Nov 16 '18 at 9:44











  • I am dynamically creating a QR code

    – omkar patade
    Nov 16 '18 at 9:49











  • Can you confirm that QR creation methods use the correct uri?

    – Fildor
    Nov 16 '18 at 9:58






  • 1





    I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

    – DavidG
    Nov 16 '18 at 10:05








  • 1





    You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

    – Sergiu Muresan
    Nov 16 '18 at 14:19














2












2








2








I am completely new in this part - I have a QR code on my screen which works for both windows and mobile i.e. you can click on that QR code to open a new window with given page in same browser on window or you can scan the QR code which will open that page in your mobile phone.



previously we have single server it was working fine. We were generating the URL for that QR code as follows -



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

return urlBuilder.ToString();


This used to return the url as "http://site.internal/Controller/Action"



This was working for both desktop & mobile



Now we have deployed app on multiple servers and got the load balancer.



Now URL of the application has changes -



E.G. Load Balanced External URL = https://secure.abc.com



Now when we generate an URL for QR code using same code then it takes the server URL i.e it points to server URL (http://site.internal/Controller/Action) instead of Relative path/current URL.



Is there a way to solve this issue? to take relative path instead of server path?





Edit - I tried changing the code as



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

var cleanUrl = urlBuilder.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Scheme & ~UriComponents.Host & ~UriComponents.Port,
UriFormat.UriEscaped);

return cleanUrl.ToString();


But it works only on Desktop. It does not work on mobile phone as there no URL present on phone when we scan the QR code










share|improve this question














I am completely new in this part - I have a QR code on my screen which works for both windows and mobile i.e. you can click on that QR code to open a new window with given page in same browser on window or you can scan the QR code which will open that page in your mobile phone.



previously we have single server it was working fine. We were generating the URL for that QR code as follows -



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

return urlBuilder.ToString();


This used to return the url as "http://site.internal/Controller/Action"



This was working for both desktop & mobile



Now we have deployed app on multiple servers and got the load balancer.



Now URL of the application has changes -



E.G. Load Balanced External URL = https://secure.abc.com



Now when we generate an URL for QR code using same code then it takes the server URL i.e it points to server URL (http://site.internal/Controller/Action) instead of Relative path/current URL.



Is there a way to solve this issue? to take relative path instead of server path?





Edit - I tried changing the code as



 var urlBuilder = new System.UriBuilder(HttpContext.Request.Url.AbsoluteUri)
{
Path = Url.Action(actionName, controllerName),

Query = "ID=" + model.abc
};

var cleanUrl = urlBuilder.Uri.GetComponents(UriComponents.AbsoluteUri & ~UriComponents.Scheme & ~UriComponents.Host & ~UriComponents.Port,
UriFormat.UriEscaped);

return cleanUrl.ToString();


But it works only on Desktop. It does not work on mobile phone as there no URL present on phone when we scan the QR code







c# asp.net-mvc-4 uri load-balancing qr-code






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 9:31









omkar patadeomkar patade

55372042




55372042













  • Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

    – Fildor
    Nov 16 '18 at 9:44











  • I am dynamically creating a QR code

    – omkar patade
    Nov 16 '18 at 9:49











  • Can you confirm that QR creation methods use the correct uri?

    – Fildor
    Nov 16 '18 at 9:58






  • 1





    I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

    – DavidG
    Nov 16 '18 at 10:05








  • 1





    You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

    – Sergiu Muresan
    Nov 16 '18 at 14:19



















  • Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

    – Fildor
    Nov 16 '18 at 9:44











  • I am dynamically creating a QR code

    – omkar patade
    Nov 16 '18 at 9:49











  • Can you confirm that QR creation methods use the correct uri?

    – Fildor
    Nov 16 '18 at 9:58






  • 1





    I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

    – DavidG
    Nov 16 '18 at 10:05








  • 1





    You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

    – Sergiu Muresan
    Nov 16 '18 at 14:19

















Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

– Fildor
Nov 16 '18 at 9:44





Do you dynamically create the QR using that same url? Or is it a fix image? If the latter, then you need to change to the former.

– Fildor
Nov 16 '18 at 9:44













I am dynamically creating a QR code

– omkar patade
Nov 16 '18 at 9:49





I am dynamically creating a QR code

– omkar patade
Nov 16 '18 at 9:49













Can you confirm that QR creation methods use the correct uri?

– Fildor
Nov 16 '18 at 9:58





Can you confirm that QR creation methods use the correct uri?

– Fildor
Nov 16 '18 at 9:58




1




1





I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

– DavidG
Nov 16 '18 at 10:05







I assume the load balancer isn't passing through the URL being requested by the browser? Have you tried this?

– DavidG
Nov 16 '18 at 10:05






1




1





You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

– Sergiu Muresan
Nov 16 '18 at 14:19





You could add the external url in appsettings from web.config and replace HttpContext.Request.Url.AbsoluteUri with Configuration.AppSettings["ExternalUrl"]

– Sergiu Muresan
Nov 16 '18 at 14:19












1 Answer
1






active

oldest

votes


















0














After doing some research, only way i found is to keep the external url key in web.config and replacing the absolute uri with external url key.



Other way is by assigning that value to environment variable on server






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334957%2fc-sharp-qr-code-link-in-case-of-load-balancer%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    After doing some research, only way i found is to keep the external url key in web.config and replacing the absolute uri with external url key.



    Other way is by assigning that value to environment variable on server






    share|improve this answer




























      0














      After doing some research, only way i found is to keep the external url key in web.config and replacing the absolute uri with external url key.



      Other way is by assigning that value to environment variable on server






      share|improve this answer


























        0












        0








        0







        After doing some research, only way i found is to keep the external url key in web.config and replacing the absolute uri with external url key.



        Other way is by assigning that value to environment variable on server






        share|improve this answer













        After doing some research, only way i found is to keep the external url key in web.config and replacing the absolute uri with external url key.



        Other way is by assigning that value to environment variable on server







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 19 '18 at 12:52









        omkar patadeomkar patade

        55372042




        55372042
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53334957%2fc-sharp-qr-code-link-in-case-of-load-balancer%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python