C# - QR code link in case of load balancer
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
c# asp.net-mvc-4 uri load-balancing qr-code
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
|
show 1 more comment
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
|
show 1 more comment
1 Answer
1
active
oldest
votes
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 19 '18 at 12:52
omkar patadeomkar patade
55372042
55372042
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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