why do not show alias name in iis? - c#

I create a website by Visual Studio and publish it.
Then in IIS I do:
dd application and
set alias name to CIP and set physical path.
Home page is loaded correctly but other pages have wrong URLs in addressbar.
This is homepage URL: "http://localhost/CIP/Pages/Default.aspx".
When I click on the other link showed below link without CIP(alias name).
"http://localhost/Pages/OperationPersonelProgram.aspx".

You need to have your application make sure that the URLs it's using make sense. This requires some server side code to execute. So, if you're writing an MVC website you would use the UrlHelper class, something like:
<a class="link" href="#Url.Content("~/Pages/HostessPersonalProgram.aspx")">mylink</a>
(The above is Razor syntax, but similar should be possible).
Most of the different "styles" of ASP.Net offer a similar shorthand for obtaining the correct URL, but if all else fails you can always use VirtualPathUtility.ToAbsolute:
var url = VirtualPathUtility.ToAbsolute("~/Pages/HostessPersonalProgram.aspx");

Related

.Netcore api with ReactJs dynamic URL Pathname

I'm currently in the process of converting project frontend from .netcore web application (razor page) to reactjs, one of the road block we encounter is the dynamic url path that we applied in razor page.
As the application is deployed on IIS under default website, so the url is construct as https://localhost/Project. One of the project requirement is it can to be replicate and deploy many time, so there will be https://localhost/Project{n}. That mean the url path name need to be configurable so the frontend JavaScript will request to the correct api url. What i done was config the pathname in iis application's webconfig and inject it into the razor page, so javascript can refer to the injected pathname variable.
But when come to reactjs, it is a seperate project from backend but they share the same url, and reactjs has no way to get the configurable pathname so it can only stick to whatever set in the public_url/homepage, and it can only be set before project is build. As it is not set dynamically, the frontend point to the right default page but wrong javascript url, so it cant even run the react main chunk js.
Any lead for me to continue on? Or i need to change the way of configurable pathname?
In React you can use standard JS. So in order to get the current path name from your React application, you can do something like:
const pathname = location.pathname
If you need the pathname in many different places in your React project, you can set it as a context. (See this documentation)
Alternatively, if you only need it on the initial load, you can just do a useEffect in your app.js file like:
const {pathname, setPathname} = React.useState();
React.useEffect(()=>{
setPathname(location.pathname);
}, [])

Removing Localhost url in asp mvc

Just having a problem trying to properly display an image from an external site but mvc constraints links and automatically adds the localhost: url at the start of everything even with custom routing this cannot be avoided
eg I require: www.google.com/finance/chart?q=NYSE:V&tlf=12
but i am getting: http://localhost:3022/www.google.com/finance/chart?q=NYSE:V&tlf=12
any help would be much appreciated
Your problem is not MVC; it is the formation of your <a> tags. You are doing it like this:
blah...
You should be doing it like this:
blah...
Without including the protocol at the beginning, the browser assumes your link is relative to the current site. It has nothing whatsoever to do with MVC.
If you require a link on a separate domain, you need to add http://
So :
http://www.google.com/finance/chart?q=NYSE:V&tlf=12
Should work!
Why? Without the http, the link is considered relative and the browser uses the relative domain -> localhost!

URL Rewriting in asp.net c#

I'm working on a real estate website. It would be ideal to have my client's featured properties have their own unique URL like:
www.realestatewebsite.com/featured/123-fake-st/
I'm constructing a CMS for my client so that they can add/delete featured properties in an admin backend, meaning that I need to write a program to automatically add the new URL for them based on the address they input in the database through the CMS.
I'm new to URL Rewrite. What would be the best way to go about this? I've considered using RewriterConfig in the web.config, but then I'm worried I would encounter problems writing a program that adds new rules to the web.config file. I thought about using a regex expression in the RewriterRule to find anything after /featured/ in the URL, but then if I'm just using the address in the LookFor then how would it know which property ID to use in the SendTo?
It would be ideal if I could just have a file put the address after "/featured/" into a string, look in the database for the address and retrieve the Property ID and then redirect the users that way.
As I said, I'm new to URL Rewriting and it would be great if someone could point me in the right direction.
Thanks!
-Aaron
There are different ways of doing this. Common to all solutions are the following:
Set up a algorithm to create the URIs and store them in the database (changing space to - is a simple way to achieve this.
Route the URI by making the address string into a parameter
Routing can be done a variety of ways.
If you have control of the server, or they have control of the server, you have the ability to set up IIS rewriting on the IIS instance on their server (good starter URI).
If this is hosted on an ISP, you may not have this option and have to use IIS rewriting and will have to use ASP.NET routing. Here is a good article to start with to undestand this. If you are using MVC, the routing is "built in".
I would suggest using URL Rewrite Module for IIS7, look here:
http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/

Parse Subdomain on localhost

The Setup
I am building an app using ASP.NET MVC3, the application makes use of sub domains, i added the following in my hosts file : 127.0.0.1 students.localhost.
This all seems fine, when i debug, the browser opens up localhost:{PORT}, i can browse the site, i can also open up: students.localhost:{PORT}, and the site works perfectly.
In case you were wondering, i made use of: Maarten Balliauw's code to achieve the routing requirements in MVC and subdomains
The Problem
I need to somehow find out what subdomain the user is accessing the site from. If i debug, my and go to my subdomain:http://students.localhost:{PORT} Request.Url is : http://localhost:{PORT}, for some reason the deubugger (or ASP.NET Development Server) is not picking up students.
Please do not go into the TLD descussion trying to explain what a subdomain really is, all i need is the first string after http://. in local and production this WILL be my subdomain.
Thanx in advance
UPDATED:
I managed to get the desired result by making use of:Request.Headers["host"], it would be interesting to find out why Request.Url does not contain the students substring.
The easy way to do this is to put a fully qualified domain name in hosts. If the production site is subdomain.domain.com, I like to use subdomain.domain.local and just map this to 127.0.0.1.
new System.Uri(Request.RawUrl).Host
I think this will be the real hostname.

URL routing relative paths with webforms ASP.net 4 and IIS6

I am try to get routing configured on an asp.net 4.0 site running on an IIS6 server.
I am using MapPageRoute and it takes me to the correct page. Problems I have encountered so far:
Extensionless Url Routing
Solved by installing QFE described here Link
Static content such as js, css and images not displaying
Solved using Chris Cavanagh's baseUrl technique described here chriscavanagh.wordpress.com/2008/11/06/aspnet-routing-just-enough-rope/
Relative urls and postback scenarios
NOT SOLVED. For some reason, relative paths are not being interpreted correctly. For example. asp:ImageButton runat="server" ImageUrl="~/images/tree.jpg" is rendering out as and img with src="". I have been able to force it to work by setting the ImageUrl to an absolute path but I can't do this for everything. It is also affecting postback scenarios. Button clicks are taking me from (eg) localhost/website/articles/the-article_description/ to localhost/website/the-article-description which does not exist.
Can anyone help me out with this?
For situations like #3, I have been placing a function there that returns a string to be used as a prefix URL for the production site. So for this part where you have:
mageUrl="~/images/tree.jpg"
adjust it to this:
mageUrl="<%= [YourNameSpace].AppMethod.IsProd() %>/images/tree.jpg"
'AppMethod' is some static class and the IsProd() function returns the prefix necessary to specify the production path if the app is running in production. Otherwise the prefix "~" if the app is running in dev. You can determine if the app is running in production by reading the machine name.
do you have the RouteExistingFiles property set to true?

Categories