What is the meaning of # in this url - http://projectname/controller/viewname# - asp.net-mvc

On clicking the submit button of a asp.net mvc webpage, it does not show any change other than #sign succeeds my webpage url like this - http://projectname/controller/viewname# Why?

It refers to a specific anchor in the source page.
I wouldn't worry about it

Related

if i use querystring on a page navigateurl redirecting in a samepage

I am trying to click on a link in products.aspx and redirect to another page categories.aspx. When i use {*id} in routing to handle querystring on products.aspx link is not working well. Sending same products.aspx page.
My Routes:
routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");
routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");
Hyperlink in products.aspx page:
<asp:Hyperlink ID="hyper_link" runat="server" NavigateUrl='<% GetRouteUrl("productscat", new {bname=Eval("brand-name").ToString()})%>' Text="Category1"></asp:Hyperlink>
Hyperlink is in a asp:Repeater and Eval() is working fine on a link and link is seems normal, when i click on the hyperlink, url changes but not sending categories.aspx page.
If i delete querystring {*id} and not use than hyperlink works fine.
I am trying to understand why it's happening and what we can do about it.
There is a simple solution. Change route order and your target url and link will work.
routes.MapPageRoute("productscat", "products/brand/{bname}", "~/categories.aspx");
routes.MapPageRoute("productsgroup", "products/{groupname}/{*id}", "~/products.aspx");
Routing thinks target url is "productsgroup" because it knows the url and target url starts like that. Routing waits for the variable and second route like it doesn't exist for routing.
I hope it helps. Cheers.

How to categorize links without changing the URL

I'm re-building a site that's had lots of SEO work done to it. Currently built in ASP.NET web forms, I'm re-building in ASP.NET MVC.
All links have been "re-written" for SEO purposes. Examples:
- If you search for "foo", the search result URL will be "foo-stuff-for-sale", if you search for "bar", the URL would be "bar-stuff-for-sale" - you get it.
- The search results are "categorized" - i.e. categories are "widgets", "clocks", "clothing"...where the search term is contained in some portion of the products under each category
- If you click on a link from a category, the resulting search page would go back to the same search result, but without the category that was clicked on. i.e. - search for "foo", click on a link under "widgets", you'd go back to "foo-stuff-for-sale", but the "widgets category wouldn't show.
With Web Forms, this was being accomplished by a property in the .ascx page that was displaying the links and would be stored on the link itself somehow so that the link handler would be able to grab it and omit stuff from that category.
How do I accomplish the same thing using ASP.NET MVC and razor templates?
I've thought about:
Cookies - set the cookie using jQuery.cookie on click from a "data-category" attribute, read the cookie in the controller and then remove the cookie on display.
jQuery - setting something else on the query string onClick that the controller can read, but then doesn't show in the URL upon display.
UPDATE: Additional context: This was done in the old implementation via a session variable. I'm doing all I can to get rid of session state for this new implementation.
Thoughts? Ideas?

How to get URL while navigating to other site

I am developing a test where I need to validate the URL while its navigating to the retailer's site
For instance, when I click the Product, it navigates to retailer's page. I need to capture the URL when it is navigating to the retailer's page but it should not be of the previous page & even not of the retailer's page.
Is there any method in Ruby or Capybara to get that URL? I have tried to implement this method but it's not giving the correct URL.
url = URI.parse(current_url)
def validate_url(url)
browser= Capybara.current_session.driver.browser
puts "current URL = #{browser.current_url}" if #verbose
assert_includes browser.current_url, url
end
#Actual Output url =http://www.shopstyleqa.com/browse/womens-clothes
#Expected Output url=http://www.shopstyleqa.com/action/loadRetailerProductPage
Since Capybara is designed to emulate a users use of a browser it doesn't report on redirects so there is no way to get the intermediate url if the browser is being redirected to a different one. You could verify the original URL that is going to be requested if it's in a links href attribute or a data attribute on whatever element represents the project, etc.
On a side note comparing current_url with eq or includes is a recipe for flaky tests. Instead you should use the assert_current_path assertion which uses Capybaras waiting/retrying behavior - In your case it would be something like
assert_current_path("http://www.expected.com/expected_url", url: true)

URL redirection JSF

I have my my app url: 127.0.0.1:8080/reader/read.xhtml
The read.xhtml is populated thorough database and has got various
links which are hard coded in database. (read.xhtml is actually
retrieved as String from DB.) for e.g. there are links
(<a href ="/write.xhtml>write</a>)
/write.xhtml
/upload.xhtml
as I cannot add the context when i click the link it directs me to
WWW://127.0.0.1:8080/write.xhtml or
HTTP://127.0.0.1:8080/upload.xhtml
Is there any way I can redirect the link to
HTTP://127.0.0.1:8080/reader/write.xhtml.
Can Prettyfaces handle this. If yes how?
You can simply add the context path to the links by rendering it in front of your links. Something like:
write

JSF login forward address bar / url -- redirect does not solve problem

Okay we have a single - sign - on and the user will likely enter www.blabla.com/AppName/ to reach our site. We then define a welcome site, use a phaselistener to check:
is user trying to access the welcome site? yes -> try to login - works? yes -> get user roles -> forward to the appropriate site for this specific user.
E.g. user niceBelly goes to page /somewhere/in/many/folders/beer.jsf and user barbie goes to /breasts/pink.jsf
a redirect is in this application not possible for some reasons.
the result is that when reaching e.g. page pink.jsf the address bar still shows blablaba.com/AppName/
clicking the first link will result in the browser using the form address as new URL e.g. on welcome.jsf i navigate to coolstuff.jsf. On the page coolstuff i now have the url of the last form, e.g. welcome.jsf. Then on cool stuff i click a link, and get coolstuff on the next page as url, and so on.
Is there a way to solve this / work around it?
Given the symptoms, you are actually not redirecting the requests, but you are actually forwarding the requests. A real redirect will take place when you call
externalContext.redirect(url);
in JSF context, or when you add
<redirect />
to the navigation case. All other ways are effectively forwards. As per the symptoms, you're using commandlinks instead of outputlinks to navigate to other page. Commandlinks will submit a POST request to current URL and JSF will under the covers use RequestDispatcher to set the destination of the request/response when the navigation case doesn't contain <redirect />. A forward does not instruct the browser to fire a new GET request on the destination URL and hence the URL in browser address bar does not change. A real redirect will do exactly that.
See also:
When should I use outputlink instead of commandlink?
Bookmarkable URLs in JSF 1.x

Resources