Ajax url after publish site - c#

I developed a site in asp.net. In my site, I have an ajax post which worked when I ran the site locally.
After I publish my site, it looks like the url for ajax post is changed.
I want to align the URL that when running the site locally will be the same as when the site is published
I published the site under folder name ResourceManager (it also the site name)
My ajax URL before publish the site
URL= "/testbed/ConnectTesbedToResource/";\\(<controller_name/method_name>)
after publish the site its NOT working and I need to change the URL to
URL = /ResourceManager/TestBed/ConnectTesbedToResource/;
How I can make sure that the URL will be the same for local run and for publish run?
I tried to change the URL to relative path with ~ (~/testbed/ConnectTesbedToResource/) and it also didn't work.
How can I make that after publish I will have same URL for jQuery post request?

Use URLs without a / at the start - / will make it relative to the site root, which, as you've seen, can change depending on the config of the server and where you install to. Without the / it will be relative to the current page, which is much easier to handle across different install locations

Related

Configure URL Redirection With Azure Active Directory

I have Deployed a MVC Application that use ADD Login for authentication.
now I have problem to continue work on my localhost as I am redirected to the actual website, just after login in.
I can configure redirection in Azure portal, under app registration, but that requires me to change url everytime I want to do some work, and makes actual website not working for that time.
I won't to be able to run app on my local host, but keep the deployed one still working.
but that requires me to change url everytime I want to do some work, and makes actual website not working for that time
If I understand you correctly, the url you mean the Redirect URI in the portal. If so, you don't need to change it every time, you could configure both of the Redirect URIs you need in the Redirect URIs list like below.
Then when you run your app in local, you just need to change the redirect_uri in the authorization URL when the user login. It will not affect the app in the cloud.
Sample(url encode for http://localhost:3000):
https://login.microsoftonline.com/{tenant-id}/oauth2/authorize
?client_id=ef92a29b-b332-9d43-1341-23326315fa42
&response_type=id_token+token
&redirect_uri=http%3A%2F%2Flocalhost%3A3000
&state=12345
&nonce=678910
&resource=https%3A%2F%2Fgraph.microsoft.com%2F

Issue in routing in existing ASP.NET application

I have a problem with routing in an existing ASP.NET application for work. I have the code for the application and i can build and run it. When i run it I see the home page, but all links and images have invalid URL's. For each URL the same problem occurs.
For example an image on the home page has this src:
src="/appName/Images/img.jpg".
but the image is actually at "/Images/img.jpg". Notice the missing '/appName', this is the problem with every link / image.
The root folder of the application is in the folder '/appName', but the URL's/images seem to think it is one folder above that.
Now I could change every URL and take out the '/appName', but I feel like it should be possible to run the website correctly without changing the code. Maybe i should change something about the environment or IIS express.
HttpContext.Current.Server.MapPath("~") returns the path to the /appName folder. So the img src and a href start looking in /appName/appName which doesn't exist.
I have searched online, but cannot find anything.
I've already tried changing the root URL in applicationhost.config, but this resulted in IIS not finding an application in that folder.
I know the website works in the production environment, though i currently have no access to the production environment. But i do think it is an environmental setting (maybe in IIS).
So does anybody have an idea how to change it so the links think the root URL is one folder above the actual root folder in IIS?

Error: redirect_uri_mismatch In Google Login in MVC Application

I am trying to upload video to YouTube through MVC C# application. I am following this link
Whenever I am trying to run the application I am getting below error from the Google.
Error: redirect_uri_mismatch
The redirect URI in the request, http://localhost:52271/authorize/, does not match the ones authorised for the OAuth client. Visit https://console.developers.google.com/apis/credentials/oauthclient/CCC-XXX.apps.googleusercontent.com?project=XXXX to update the authorised redirect URIs.
Here is my Json file.
Here is my Google Console Application:
Error:
Is there anything wrong ?
Thank You.
The redirect URI you set in Google Developer console must exactly match where you are sending the request from. If you notice the Port number is changing. This is because visual studio has a habit of adding random port numbers when you are debugging via visual stuido.
To specify a port for a Web application project that uses IIS Express
In Solution Explorer, right-click on the project and then select Properties. Click the Web tab.
In the Servers section, under Use Local IIS Web server, in the Project URL box change the port number.
To the right of the Project URL box, click Create Virtual Directory, and then click OK.
In the File menu, click Save Selected Items.
To verify the change, press CTRL+F5 to run the project. The new port number appears in the address bar of the browser.
How to: Specify a Port for the ASP.NET Development Server
From Google doc located at https://developers.google.com/identity/protocols/OAuth2UserAgent?hl=en_US#example
The REDIRECT_URI should be the same URL where the page is being served.
I finally saw this, put the URL for the page where I call the Google authentication, and it worked like a charm.
You need to add localhost to your authorized domain names in the Google API Console.

Get Site URL stored in solution properties SiteURL

Currently working on creating custom function for a SharePoint site, i have inserted Site URL on the SharePoint project folder, is it possible i retrieve the Site URL from the project properties to use in .cs file within it?
Site URL in a project you set for the possibility to deploy solution to SharePoint via Visual Studio. If you want to get current Web url from code you can use SPContext:
SPContext.Current.Site.Url - for the site collection url,
SPContext.Current.Web.Url - for the current Web url.

How to route an url to local directory? (Description inside)

I had a site in which all the images are inside a sub directory in my site. But I need to save those pictures in a specific directory and I need to show the in a client application which holds my page url.
for example: I had an url, http://foo.example.com/images/happy.jpg
the site is in c:/Example.
i'll store the images in c:/Images/categories/category1/happy.jpg
if my client request the above url, I need to redirect it to the image in the folder, where I kept all my images.
can somebody say is this possible? If possible, please suggest a way to accomplish this through url routing
The easiest way to accomplish this is to add a virtual directory to your IIS configuration for the folder where the images are held. Once the virtual directory is added you can reference the files via a URL to the virtual path. This is the best way in a production enviroment.
Technet step by step guide to adding a virtual directory
As for no authorization, you should select "Application User" (pass-through authentication). If you nest the new virtual directory inside the application's VD, you may need to add a web.config file to the virtual directory to override any authorization/deny rules in the root web.config file.
For local debugging, if the images are on your local PC, you can use a file:/// url replacing c:\ with file:/// and forward slashes instead of back slashes for the rest of the path. Don't forget to escape the slashes in the code behind by using "#".
Alternatively, a more involved solution would be configuring local IIS similar to above and using local IIS instead of the ASP.net runtime server which uses localhost:port using the link above and configuring your project to use IIS. If you are building this project over a long period of time local IIS makes the most sense. Short projects can be easily done without local IIS.
How to configure a project to use Local IIS for debugging

Categories