How to redirect page from HTTP to HTTPS(IIS and Code methods)? - asp.net

I was searching on web for this solutions and found so many solutions. Some of you might merge this with other question as duplicate(i dont mind), but there are some general questions i have as newbee which help me to understand this process and also other can use this. So my website works on both http(80) and https(443). I want my login and edit profile page to always redirect to HTTPS. I dont care about other pages.i binded the SSL and works fine with http and HTTPS.My application is in ASP.net and server is Windows server 2008 with IIS7
So there are two ways i found through which you can do this. 1) Through IIS and 2) Through Code (Other methods are welcome)
My first question is which option is more feasible or optimal? I saw some of the comments with IIS and MS URL redirect module says they have problem redirection in some IE. And for code based solutions i am wondering is this the best method you can use.
I saw some commets which says if you have dynamic URL then IIS method might give you error for some URL with data.
Second is pros and cons of these two methods? So other can use one of those method according their needs
here are some of the answer i got from web
http://raoulpop.com/2007/08/07/automatic-redirect-from-http-to-https/
This is IIS method
http://www.sslshopper.com/iis7-redirect-http-to-https.html
and i can go on with these solutions. But what i am asking is which is better way, ISS or code? You are welcome to post your ideas and your solutions which help me and other to understand this problem better.
Thanks in advance.
Arpan.

Related

ASP.NET (C#) do a post to page from code and go to that page

I am very new to .NET and am now in need to modify an existing ASP.NET website done with C# long back by someone else (with .NET version 2.0).
There are lot of process involved in this website and I need to get few data from the database and then do a POST to another page from the code itself. I am able to do a redirection to required page with necessary parameters, but need to implement the same with POST.
Can anyone please guide me on how to implement this? Thank you.
After few more searches on my requirement, came across another Stackoverflow post - https://stackoverflow.com/a/2802848/2451196.
This was a much straight forward approach for me and it worked like a charm. Thanks to Pavlo Neiman (https://stackoverflow.com/users/164001/pavlo-neiman)

Possible bug/issue in ASP.NET 3.5 related to Request.RawUrl property

I posted a query for 301-redirect using ASP.NET 3.5 here:
Redirecting default.aspx to root virtual directory
Based on the replies I got there, I realized there might be a bug in ASP.NET's Request.RawUrl method which is unable to return the actual raw url (without /default.aspx) when being used in a sub-directory, i.e. the /default.aspx page is inside a subdirectory.
Can someone please shed some light on this possible bug?
Thanks,
Asif
i found a good explanation here
http://codeasp.net/blogs/vivek_iit/microsoft-net/873/301-redirect-from-default-aspx-to-site-root
Thanks
If you suspect this is a bug, then the place to go is Microsoft Connect, where you can report and discuss the bug directly with Microsoft.
Edit: I was able to reproduce the look per your comments.
I was unable to reproduce the infinite loop, however. I injected code into the Global.asax Application_BeginRequest handler of a web application and got the expected behavior of a single redirect.
There are other, and IMO much better, options for handling global redirect rules. On IIS7, I use the URL Rewrite module to configure rewrite rules in IIS. You can read more about it and download it here: http://www.iis.net/download/urlrewrite. The appeal of a solution such as this is that you can customize and update your rewrite rules without recompiling the application.
Edit: I was able to retrieve the raw URL without the default.aspx (after the redirect) by using instead:
Request.ServerVariables["CACHE_URL"]
It's worth a shot.
Have you looked at the IIS settings for your virtual directory? If there is a default document set to default.aspx then this will explain the infinite loop that you are experiencing. You are telling the website to redirect to the virtual directory without the "default.aspx" and IIS is detecting this on the next request and putting it back in ad infinitum.
Right click your virtual directory, select Properties and then the Documents tab. If default.aspx is in the list then that is what you will get. The Url of the request will be passed to the ASP.NET worker process as /folder/default.aspx rather than /folder/
This is not a bug. If IIS didn't do this, you would get a page not found error.
Sounds to me like you need to investigate URL rewriting: http://msdn.microsoft.com/en-us/library/ms972974.aspx

My hosting is messing up my urls

Usually when I get the url of a request i use Request.RawUrl.
This gives /default.aspx for example.
However recently my host changed something and now the name of the application directory is displayed as well so i get /appdirname/default.aspx.
Now why does it give me the directory of the application? It looks as if my website is a subapplication of another website. So when you go to mydomain.com the rawurl will be:
/appdirname/default.aspx
I believe each domain has it's own website defined in iis or am i mistaken.
I am not asking for a workaround, which should be pretty straightforward, I am asking why this is happening and how, what kind of IIS setup causes this to happen?
PS.
And the worst part is i had this issue with godaddy and i was happy my host didnt have it but now both hosts have the same problem.
The Request.RawUrl method returns everything after the domain declaration, so if your full url is:
http://www.yourdomain.com:8080/directory/Page.aspx
then the method will return
/directory/Page.aspx
That's all it does. That's all it claims to do. As you say, your hosting provider must have changed something, which is very naughty, and the workaround should be easy. There is a good chance that they have introduced some kind of url redirection, but the best way to find out is to get in touch with their helpdesk and ask them what is happening. I find that most successful hosting companies tend to respond in good time to this kind of question. Otherwise they tend to become formerly-successful hosting companies.
Ric Strahl has this to say about it: http://www.west-wind.com/weblog/posts/132081.aspx

How to SEO friendly an existing ASP .NET 3.5 web application under IIS6

So, I know there's a lot of this subject here and over the Internet. But most articles/questions refers to "static" url rewriting, like:
www.site.com/products.aspx?category=Books
So they rewrite it to
www.site.com/Products/Books
That's ok but I need something else.
The site is like a CMS, it has different types of content.
Nowadays to read the article titled "How StackOverflow helps you in your development" you need to go to an URL like the following.
www.site.com/viewContent.aspx?Id=1234
What I want to achive is:
www.site.com/Content/Articles/how-to-stackoverflow-helps-you-in-your-development
So as I understand, I need to involve ASP .NET in that, because first I need to retrieve the article (an its title of course) and then rewrite the URL.
But I'm wondering how the hell ASP .NET will know how to get that article if I go to that URL, it doesn't include the id anywhere...
So maybe I could accept something like
www.site.com/Content/Articles/1234/how-to-stackoverflow-helps-you-in-your-development
I'm kind of lost here really.. I've never done any URL Rewriting at all and I've googled a lot and I cannot find a way to do what I want. Maybe what I want is not called url rewriting??? I don't know...
The site is running under Windows 2003 Server, IIS6, ASP .NET 3.5 SP1
And of course, I need a free solution, cannot spend 100usd on the ISAPI mod (besides I don't know if that is going to do what I need).
Thanks to all and sorry if this is a duplicated question, but I couldn't find it.
EDIT: I don't need to support non-ASP.NET files (jpgs, gifs, etc) don't need to be rewritten. I just need to rewrite the viewContent page to include the content title into the URL.
You can use the new Routing that comes with ASP.Net 3.5 sp1 to have clean URLs.
This can even be done in web forms and not just MVC. ( I have done it myself). See here and here for exanples of how to set it up.
You can throw the Id of the article and the title in the URL and make the Id the real parameter that gets used to search for the article. That is what SO does. Try removing the question for the URL and it will take you to the same place.
Even if you don't use the Id you can pass the title of the article "how-to-stackoverflow-helps-you-in-your-development" to your DB and retreive the article based on the title.
With regards to IIS 6 it is a little trickier since IIS 6 by default can't handle extension-less URL's.
There are a few work arounds:
Use the wildcard mapping in IIS to map all requests to Asp.Net
Put Default.aspx at the end of your urls
See this post for other possible solutions.
Although the first solution may have performance issues if all content in your site goes through Asp.Net (even images, css, .html ...) in a small site it shouldn't matter. I have used this approach and there wasn't any major performance issues. I think it is the simplest solution. Here is the website I built with it
I hope this helps.
This one is free, I have used it and it works pretty well: http://www.codeplex.com/IIRF
The nice thing is that it will handle url's without an extension (i.e. .aspx, .html, etc.)
You can achieve this with ASP.NET routing.You can do this with ASP.NET MVC as well as Webforms.No need to do anything with IIS.
Check the below link
https://web.archive.org/web/20201205221404/https://www.4guysfromrolla.com/articles/051309-1.aspx#postadlink
I did URL routing in my web application within 1 hour with the details from the above link.Its quite simple to learn .They provide sample codes too.It will help you to do it easily
You can retrieve the Id of the content using the title.But title should be unique.You can use ajax to check whether the title is a already existing one when user takes mouse out from the textbox.
Easiest way is to add a http module to your current webforms project.
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
This shows you the basics of it, But it can easily be expanded so that the pages you want to rewite is taken from a database or even built on the fly.
ASP.net MVC is your friend for that
stackoverflow use MVC

Is there any Forum or Knowledge base for Plumtree interms of hosting Asp.net as Portlets

I am quite new to Plumtree, and hosting asp.net pages as portlets is not so easy.
There are weird issues coming up every time, like
-> Session variables don't work across PAges
-> Build- in Ajax doesn;t work
-> Response.redirect fails
I would like know more on hosting asp.net pages in plumtree, Please let me know if you come across any Forum or Knowledge base for Plumtree.
Your best place would be BEA/Oracle forums for Aqualogic, LiquidSomething, Interaction, or whatever they call it now.
Explaining inner-working of Plumtree here would take forever.
The best way to do this is to use the session preference in the web service definition
B
Use session preferences. More information and details can be found here: http://download.oracle.com/docs/cd/E13174_01/alui/devdoc/docs60/Portlets/Basics/PlumtreeDevDoc_Integration_Portlets_Settings.htm
Also check out http://www.function1.com/blog for Plumtree/Aqualogic Interaction/WebCenter Interaction discussion.

Resources