page redirection c#-address bar url - c#

i have a scenario in which i want to set a page redirection from a custom url to my web site.For instance i might want http://support.mydomain.com to open page http://mysubdomain.mydomain.com/support/index.aspx but the trick is that i want the address bar to show http://support.mydomain.com and not http://mysubdomain.mydomain.com/support/index.aspx. I m using aspnet c# web forms.
Any ideas?

It doesn't sound good especially if its on your subdomain. However the answer would be to use an Iframe.

You can try using URL Rewrite. Even though, strictly speaking, it is a workaround.

You can use
Server.Transfer()
Because it doesn't change the url bar. Also
The best thing is using
Configure Url Rewrite in IIS

Related

Post values to URL without redirecting

I'm setting up an SMS service where I have to post some values,
like receiver, sender and message to a specific url at provider.
Pretty simple if I just add a button and in the button event I
make a response.redirect("...url and url parameters with values...")
But I don't want the user to be redirected to another page when the
button is clicked. I have tried to post the url to a new window with
JavaScript. This is okay, but I'm running into a lot of pop-up blocking issues with
the browser...
Is there any recomendations on how to accomplish that, I think it must
be a pretty common way to post information to payment services and such.
Best regards.
When you need to load content in to different pages without reloading you can use local storage which is now widely supported. Similar in a sense to cookies but much more flexible and up to date.
In depth look in to Local Storage here
Brief local storage demo here
I can't be sure the exact method of using this with VB or C# but I am sure if you look around you will find it. It is a little hard to tell your exact use case, but ultimately GET variables are loaded in to the page or script on load, s even if you manage to change or update the variable, that won't be accessed until next reload.
With System.Net.WebClient you can call a website without doing a redirect.
Dim result As String = New System.Net.WebClient().DownloadString("http://...")

Building SPA application. Is calling RenderBody necessary?

I'm building SPA application using Backbone.js and as its back-end I want to use ASP.NET Web API. I need only one page and this fact brings me a lot of confusion.
ApiController returns json response and as far as I understand there's no need in asp.net-specific views at all. Am I right?
Can I use plain html for my main page? Or should I use *.cshtml and put a call to RenderBody instead?
If choose the first option then how will I handle validation?
Thanks!
Well the trick is that if you want search engines to be able to index your page, or people to be able to share to Facebook with a custom icon/description, etc you'll need to serve back static HTML -- none of those bots are able to run your javascript to render the page as the browser does.
If you're uninterested in this, then yes, you can completely avoid RenderBody.

Generic Urls for set of asp.net internal pages

I am looking for a solution that will allow me to print generic url for a set of pages.
Example:
For pages - site.com/About/Contact.aspx, site.com/About/WhoWeAre.aspx, site.com/About/Members.aspx etc., user should see only site.com/About/ in the address bar.
Is that something achievable? This site is not SEO friendly and requires users to login before accessing content, also I don't expect site.com/About/ or any internal pages to resolve to any page when typed directly on browser. I am also fine if real url is printed on status bar if the user hovers on the internal links. I don't think URL Rewrite or URL Routing works here. Or may be I am missing something. Using .NET 3.5 and C#.
I am tagging sitecore because I am more interested in sitecore based solution where I have different nodes under About tree and I want users to see only upto /About in the address bar, but I think if it can be done in asp.net, I can figure out sitecore part.
As you are interested in sitecore, I can tell you how we have done custom URL in a recent sitecore build.
You need to have a custom link manager by extending the current LinkProvider.LinkBuilder sitecore class. Then you need to add your custom logic on how you would like the URL by overriding GetItemUrl and BuidlItemUrl to display URL and finally and it in the web.config for sitecore to use your custom link manager.
Absolutely, use the asp.net 4 routing engine.
This will give you exactly what you want:
http://weblogs.asp.net/dotnetstories/archive/2011/01/03/routing-in-asp-net-4-0-web-forms.aspx
EDIT: for 3.5 check out:
Friendly URLs for ASP.NET
The only way to solve this, keeping /About in the address bar, would be to create client-side code that switches out the content based on user selection.
You can do that by loading the About page and then load the content for any child pages using a postback or using ajax calls.
You could also put an iframe on the /About page, and have the navigation links point the iframe to the other pages.
I think you might be able to use the target attribute to target the iframe, or use javascript to change the src of the iframe.

How can I redirect to an URL with custom headers using C#?

I have a bunch of parameters that I need to pass onto a second page via request headers. At first I tried via JS but I found out that that's impossible (please correct me if I'm wrong here).
So now I'm trying to do it in the code-behind (via C#). I want to write a bunch of custom request headers and call Response.Redirect or something similar to redirect user to the new page.
Is this possible? If so what methods do I have to use?
Edit: unfortunately using QS parameters is not an option here as it's out of my control.
Use a Server.Transfer("somepage.aspx?parameter1=value");
There is no client redirect then.
You can try setting the headers and do a Server.Transfer - I believe that will work to - up to you, but using the querystring is a bit more readable to me and doesn't show up in the clients browser.
you need to look at state in .net their are various ways to achive state.. in a stateless environment.
i would put it in the session object on page one.. read it on page 2...
create a session object on code behind page 1
read from session object on page 2.
or if you read the msdn state documenation on request paramters this will show you the options avliable.
JS dont worry about doing tricky stuff with it.. mostly trickey is wrong.

Test for default document request?

Is there a way to programmatically know when someone is using the Default Document feature of IIS to access my page (that is, the name of my .ASPX isn't in their URL anywhere)?
The only way I can think of is check the URL (to see if it's requesting http://localhost/virtual/ instead of http://localhost/virtual/default.aspx) and consider that the default document...
Not a feature for MVC or if you have url rewriting... and I don't know if an IIS feature for this either, unless for some reason it was added as a module and available via IIS 7...
I don't think there's a way to do this. If the default document feature is used, IIS just puts the document name into the URL before passing it to ASP.NET.
What are you trying to accomplish with this? You can turn default documents off if you like.

Categories