Webforms: Redirect to home page - asp.net

I want to redirect the user to the home page without actually having to reference the static page name like this:
context.Response.Redirect("home.aspx", false);
Instead I'd like to do something like:
context.Response.Redirect("/", false);
What would be the best way to do this?

Two ways.
rename your home.aspx to default.aspx because this is the default setting inside the web server for the homepage
You have to set the home.aspx as your homepage inside your webserver. E.g. if you hosting online and have the cPanel available you can do this there.

Or another solution could be to use routing:
https://msdn.microsoft.com/en-us/library/dd329551(v=vs.100).aspx
You could setup a route for the mapping "/" to the home.aspx page, something like:
routes.MapPageRoute("HomeRoute",
"/",
"~/home.aspx");

Related

How to create sub domain in asp.net

I have a website with the name of technotecode and address is http://www.technotecode.in.
In my site around 176 people are registered, when user open his profile page URL Look like this
www.technotecode.in/user/username.aspx
Instead of above URL I want to modify URL like this
username.technotecode.in
Any one suggest me how to achieve this
You can try below url here its explain some basics about URL rewrite using controller
How to create subdomain with username using C# and asp.net?

ASP.NET Hide Site (in URL)

When I navigate through my Website and access a new Site, by example:
Default.aspx
it would show in the URL-Bar: www.mySite.com/Default.aspx
But I want to hide this! -> So each time, it should stay: www.mySite.com
How to achieve this?
You could have a look at routing. Routing will enable you to add a path like www.mySite.com to a specific aspx file.
It's quit easy to setup in your global.asax :) You can check the following url for some info ASP.NET routing
If you want every page to have your main domain name only in the url, you could create a frame in your index page (f.ex. Default.aspx, or even better index.html):
<frameset>
<frame src="default2.aspx">
</frameset>
and then create your new startpage in default2.aspx.
However, frames have disadvantages, and your visitors wouldn't be able to copy the url - they would always return to your startpage.

Replace the url without refreshing the page in .net

My default url home page is http://www.brindesbb.com/Pages/Default.aspx.
but I dont want to show Pages/Default.aspx in the address bar.
can anyone suggest me how to replace the url without reloading (refreshing ) the page.
Thanks in advance
You can do so in two ways IIS URL Rewriting and ASP.NET Routing
http://learn.iis.net/page.aspx/496/iis-url-rewriting-and-aspnet-routing/
What you want to do is URL Rewriting, read more here URL Rewriting in ASP.NET
Update: If you setup a new website(or edit the one you have) and point the /Pages directory as "root" and aspx is an default document the url will be as you want.
Technically that not possible with .net as .net is used on server side. and you need to change the URL which is on client side so... you will need to use JavaScript to manipulate the Browser URL history. Example [asp.net mvc] my url is http://localhost:123/Home/Product and I need to change it to http://localhost:123/Home/Product/301 this can be achieved by
<script>
window.history.pushState('', 'My Page', 'Home/Product/301');
</script>

how to force to default.aspx instead of www.domain.com

OK. I'm having a ridiculous problem. I'm trying to use URL rewrite to redirection from www.domain.com to www.domain.com/default.aspx.
I thought by setting default.aspx as the default document it would automatically drop the user there. But for some reason it still comes up www.domain.com.
The reason I want it to go to www.domain.com/default.aspx is that the login control on the page doesn't seem to want to work when it is just the www.domain.com. But of course if I type in the www.domain.com/default.aspx then the login works fine. The login control doesnt seem to post at all if it is www.domain.com. Anyway, I'm trying to avoid troubleshooting why the login control is not firing and just force it to land on default.aspx anytime someone tries to go to www.domain.com. I'm using IIS7. Any ideas here?
You could add something like this to your Default.aspx code behind (in your Page_Load method):
if (Request.Url.LocalPath == "/")
{
Response.Redirect("~/Default.aspx");
}
Note that the default document setting normally allows that page to be displayed under www.domain.com/ and www.domain.com/default.aspx (it doesn't do any redirecting for you).
The anwer has to do with a breaking change in ASP.NET 4. Answer was that the form action was empty action="" when on extensionless root url. but if on that same page, but had the name of the page in the url (blahblah.com/default.aspx) the action gets filled in. the easy fix for me was to put Me.Form.Action = "Default.aspx" on the page load of the home page. problem fixed.

Why won't postbacks work on my domain root?

I have a form on a masterpage which is very simple but will not work when the site is at the root.
Works fine:
www.mysite.com/page.aspx
www.mysite.com/another/page.aspx
Does not work:
www.mysite.com
I click the button and it postsback to
www.mysite.com/default.aspx
But nothing has executed, now if I try the form again on /default.aspx it will postback and execute fine.
What am I doing wrong?
It sounds to me like the default page redirection is either accidentally (or intentionally) losing all form data. I would first suggest not redirecting to a page that doesn't exist.
However, if you insist, I'd try something like URL rewriting. Hopefully a rewrite from a module will keep the form data intact, but I can't say for sure it will. Good luck!
Thanks for the reply, I just figured it out!
I am using isapi to make sure my urls are all lower case, and 301 redirecting any upper case URL's to their equivalant lowercase version.
On postback its action is Default.aspx ... My script was redirecting it to default.aspx and loosing the values before it was posted back.. DOH!
Do you have an Index.aspx at the root of your site?

Resources