tags:

views:

63

answers:

1

Hello all,

This is in VS 2005. And IIS is 6.0. I am trying to use Self signed certificate for HTTPS. In the code i am redirecting from http to https for few pages. It is nt working fine. And in the IIS manager, for each page that i want HTTPs, i have changed its setting by checking "Require Secure Channel(SSL)" and "Require 128 bit encryption".

public void setSecureProtocol()
    {
        string redirectUrl = null;
        bool bSecure = true;
        bool SecureConnection = true;
        if (bSecure && SecureConnection)
            redirectUrl = Request.Url.ToString().Replace("http:", "https:");
        else
            if (!bSecure && SecureConnection)
                redirectUrl = Request.Url.ToString().Replace("https:", "http:");

        if (redirectUrl != null)
            Response.Redirect(redirectUrl);
   }

Pages throw me an error like this

The page must be viewed over a secure channel The page you are trying to access is secured with Secure Sockets Layer (SSL).

Please try the following:

* Type https:// at the beginning of the address you are attempting to reach and press ENTER.

HTTP Error 403.4 - Forbidden: SSL is required to view this resource. Internet Information Services (IIS)Internet Information Services (IIS)

When i try to put https in the start of the URl, it wont call. I have no idea whats wrong in here. Please help me out.

Here,

Its not redirecting from http to https.

For the pages that i am not redirecting in the code behind, and changing in the IIS, i can see the HTTPS when i check the two checkboxes.

Please someone help me!!!! Thanks a lot in advance!

Internet Information Services (IIS)

A: 

@Ram I think that I found the problem.

i have changed its setting by checking "Require Secure Channel(SSL)" and "Require 128 bit encryption"

You have restrict the http for this pages, so when you call it as http, the page is not loaded at all to make your code run and redirect it to https.

So remove the restricts for http for that pages to let it run and allow the switch, and you just take care to always be https.

This is a very nice code to do that

Other way is to change all the links to the page that you wish to be secure, and send it with https, and not wait to get on that pages to change them from code behind.

Aristos
@Aristos : SO you mean, i should uncheck "Require Secure Channel(SSL)" and "Require 128 bit encryption" everywhere and see? the link is just something above my understanding levels, as i m new. :( could you please tell me in detail for the second way.I really appreciate your help. thank you!
Ram
@Ram Yes I mean that you remove all the "Require Secure Channel(SSL)" from IIS, and handle that on your code. The second way: When you have a page with a link to a secure page, then type the full path eg: (https : // www.mypages.com / login.aspx) - You need to do that on all links that leads on secure pages.
Aristos
@Aristos I have unchecked everything. and the redirection works fine. It is showing https when i go to the page but i still have the same error. It automatically redirected to https after i unchecked but why is this troubling me? Just to remind you, i am using the self signed certificate! Any other help, please?
Ram
@Ram whats now the error ? If it is just a warning, then you click on the lock icon, and you import and make safe, your self sign ssl.
Aristos
@ Aristos You are just amazing! I thank you so much for all your help. It worked for me with the way you said. i had an error in the code that made me wait. But you was perfectly right. I appreciate you! Thank you again! :)
Ram
@Ram :) cool ! :)
Aristos