how to get url entered by the user with domain? - c#

I want to get the complete URL entered by the user in the browser obviously with the correct domain name. For example, if my domain is www.TestDomain.com and the user enters the correct domain but with some extra parameters like www.TestDomain.com/Test/1124/tres. This new URL causes 404 error so i want to get this URL in the controller action method.
Thanks & Regards

Related

FromUri removing parameters

I've got some functionality on my site that if a user logs in at any given point then upon successful login they'll be bounced back to the page that they viewing. And this is all working fine except when there are parameters on the query string. To explain:
A user will be on page:
http://localhost:55432/eng/speakers/?altTemplate=Speaker&id=0030X00002QCntgQAD
and hit the login button (which takes them to another page), the URL being:
http://localhost:55432/login/?redirectUrl=http://localhost:55432/eng/speakers/?altTemplate=Speaker&id=0030X00002QCntgQAD&region=eng
As you can see I'm populating a parameter on the QS (redirectUrl)
On the login page there's a simple form that posts username and password to a method:
public ActionResult HandleLogin(string username, string password, [FromUri] string redirectUrl)
But when this method is being called the value of the redirectUrl parameter is:
http://localhost:55432/eng/speakers/?altTemplate=Speaker
i.e. everything including the ampersand has been removed.....
Would anyone know why this happens and more importantly how to stop it?
Thanks,
C

duplicate ID in aspx c# when sending emails

Im creating a tracking system in aspx c# and I want the user to submit a ticket and it'll assign it an ID and send the email.
I got everything to work but the problem is if two or more users are on the same page it'll assign them the same ID when they send the email (#150 and #150). However in Sql, it would be (#150 and #151).
aspx.cs page (Im getting the current ID from SQL)
id.Text = ds.Tables[0].Rows[0]["id"].ToString();
Then I'm incrementing it by 1 (to send the email) Because I dont want the current users that's sending the request to have an old ID.
id = id + 1;
Note that this works perfectly if only one users is on the page submitting the request.
Can someone get a work around this? Thanks!
In case you are using the logged-in user's id on the url to handle a user's session and also set the email ID (check example below):
.aspx?user_id=150&email_id=150
Then you need to use the appropriate user's session that opens your webpage as shown below to get the appropriate ID as an email ID.
id.Text = Session[user_id].ToString();
For that reason when both users are logged in simultaneously you only get the same id for both. You probably have a static site that handles only one session per user.

Get user Id in instagram

I try to using instagram api within vs using [c#,windows form] and I try with calling the url to get the access token and no problem with this issue but I need to know how to get the user id number for the authenticated user !!
In the world of HTTP Request, you can obtain everything :)
Send your request to this url to get user public info.
https://www.instagram.com/{username}/?__a=1
E.g:
https://www.instagram.com/therock/?__a=1
I got the answer
the oAuth URI will have a respnse type key with "code" as value.
then with the returned code I perform a request with other parameters like client id and client secrets..etc
read the response which will return a json object with user Id
In details see here
You may want to double check what the API response is. I would use https://www.thekeygram.com/find-instagram-user-id/. You can get the user id fast to verify its the same

How to pass query string parameter in asp.net?

I am using Access Control service (ACS). I fetched all identity providers (ip) which i set for my application using the following code :
public ActionResult IdentityProviders(string serviceNamespace, string appId)
{
string idpsJsonEndpoint = string.Format(Global.IdentityProviderJsonEndpoint, serviceNamespace, appId);
var client = new WebClient();
var data = client.DownloadData(idpsJsonEndpoint);
return Content(Encoding.UTF8.GetString(data), "application/json");
}
When user click over the signin link the above code called using ajax and get the ips and display them in jquery-ui dialog. And when user click any one of the ips for login the browser redirect to the selected ip login page. After successful login the control return to my control which i set as a returnUrl. Upto this every thing is works fine.
Now what i am trying to do is to pass some values to identity provider (ip) login page and want to get back those values at my returnUrl controller. For this i searched and came to know that there is a query string parameter known as wctx which we can set and get the value at return url. But i dont know how to do this. Can anybody please guid me how can i achieve this?
It is relatively (pretty) easy.
Your URL for listing IdPs looks something like this:
https://[your_namespace].accesscontrol.windows.net:443/v2/metadata/IdentityProviders.js?protocol=wsfederation&realm=[your_realm]&reply_to=[configured_return_url_for_your_rp]&context=&request_id=&version=1.0&callback=
This is the most complete request for list of Identity Providers. Your may miss some variables (such as context, or reply_to), but what I show is the complete request.
So now you have two options:
inclide your own reply_to parameter. It must be withing the configured realm. So if your realm is https://www.mygreatapp.com/, your default return URL would probably be something like https://www.mygreatapp.com/returnUrl/ (if your controller to handle ACS response is returnUrlController. Now, you can safely change the reply_to to be https://www.mygreatapp.com/returnUrl/?foo=bar, just make sure you URL Encode the query string.
Use the context parameter. It is safer to use and I would suggest using it. Now your URL for fetching list of IdPs will be something like:
https://[your_namespace].accesscontrol.windows.net:443/v2/metadata/IdentityProviders.js?protocol=wsfederation&realm=[your_realm]&reply_to=[configured_return_url_for_your_rp]&context=[your_custom_string_value_which_you_may_even_encrypt]&request_id=&version=1.0&callback=
Note the now there is context value present in the request for IdP list ([your_custom_string_value_which_you_may_even_encrypt]). In your returnUrl handler controller, you can check for it with code similar (or equal) to the following:
if (ControllerContext.HttpContext.Request.Form["wresult"] != null)
{
// This is a response from the ACS - you can further inspect the message if you will
SignInResponseMessage message =
WSFederationMessage.CreateFromNameValueCollection(
WSFederationMessage.GetBaseUrl(ControllerContext.HttpContext.Request.Url),
ControllerContext.HttpContext.Request.Form)
as SignInResponseMessage;
if (!string.IsNullOrWhiteSpace(message.Context))
{
// do whatever you want with the context value
}
}
You may want to perform any/more additional checks while handling the SignInResponse from ACS.

Validate domain name

I have a text box where the user can enter an URL, I would like to validate the user input such as the url is in the same domain as the application (specified in web config).
i would like to use javascript to validate this with regular expressions.
The domain name is "http://www.example.com" and user input that i m expecting is "http://www.example.com/folder".
the domain name is stored in the Webconfig AppSettings sections.
How about an alternative approach? Instead of asking for the full URL:
URL: [http://example.com/foo/bar]
instead ask for a relative URL and only let the user fill in the part after the host:
URL: http://example.com/[foo/bar]
(where [xyz] indicates the input box)
Try
location.href.match(/^http:\/\/(.+?)\//)

Categories