Friends

I have a login form. After successsful login, I have to redirect the user to welcome.aspx.

While doing this, the URL will be http://www.mangabooks.com/welcome.aspx

but I need the URL to be encoded like http://www.mangabooks.com/sdDFREdsfefrvgrwghWr34r

How can i do that?

Any help will be appriciated...

TIA.

Why would you need to do that?

@Ketsuekiame,
I dont want to make the user to view the file name... All they can see from the path must be only the domain name.

But, if you encode the website uri, then the page name effectively becomes the encoded value. You don't actually gain anything other than obfuscating the original filename...

You could do it using symmetric encryption and a datetime stamp salt to vary the generated content, decrypt that and load your page. But considering that this is so much work for what I'd consider to be no gain, please consider the actual requirement as to why you need to obfuscate the file name.

I was just thinking of encrypting a part of the url and posting it in the URL region of the browser. so that it will be directed to a common page from where the encoded page name will be got and decoded and redirected to that page.

Just as the same as a middle-man service to encryption and decryption purpose of the data. I was just thinking about the possibility of doing that. If possible I am going to give it a try.

I know that there is no gain in it, but I need to try that logic to gain knowledge...

Well it's certainly possible, but you will need to adjust your routing so that you only ever have the root controller. When you retrieve the encoded section, you will need to decode it and load the appropriate view.

This can all be done in MVC 4

@Ketsuekiame:

Fine then.

I have a scenario.. Can you please tell me whether It can be done in the following scenario.

My applicaion consists of an login form,welcome form and a mid.cs file. The mid.cs file contains the encode and decode functions. I got the steps until the url is encoded. Now the doubt is about is it possible to change the URL of the page to the encoded URL?

Hmm, if you're not using MVC then I honestly don't know. I can't imagine why not. If you have a general landing page, your links out of the page need to be your encoded values.
When you post to the page, you send your encoded values and then decode them with your mid.cs file. Once decoded you should be able to select the appropriate file for rendering.
As you will need to redirect your output, I don't know how this will be handled in normal ASP.NET (WebForms). In MVC, you can set the View explicitly so that the target filename will never be displayed.

I will ask a mod if your question can be moved to the ASP.NET forum, they might be able to give you a better answer than I can.

@Ketsuekiame:
Are you referring to the ASP.Net forum in Daniweb?

Yes, which is now where your thread is located :)

k k.. Thank you...

Now lets see what help can i get here... :)

I don't know how this will be handled in normal ASP.NET (WebForms).

If you are using ASP.NET web forms, you can use the URL Rewrite module to help you with this.

What i would invision is that you need to direct all of you traffic to one page, then use some code in the Page_Load subroutine access the querystring (from the rewrite see below), then use the query string and decode the value, then based on the results, use server.transfer("newpage.aspx").

ASP.NET will show the user the contents of newpage.aspx, but will not change the URL in the address bar. If you perform a response.redirect, it would.

The URL rewrite code in your web.config may look something like this...

<rewrite>
      <rules>
        <rule name="Decode" stopProcessing="true">
            <match url="^([_0-9a-z-]+)" ignoreCase="true" />
            <action type="Rewrite" url="landing.aspx?q={R:1}" />
        </rule>          
      </rules>
</rewrite>

please note that i wrote this from memory...i've never attempted to build a process that you have desribed, but I dont see why it wouldnt work.

Again, to get this to work, you need to have the URL Rewrite module installed on IIS.

You probably need to tweak the URL rewrite code above because not every URL will be incoded correct? How will the user access basic pages like home, about, etc..?

@JorgeM,

you need to have the URL Rewrite module installed on IIS.

I am using Visual studio 2010 to develop thi application. So I think there is no necessary of IIS installation. And also I am working in a office system, which does not allow an employee to easily install products.

You probably need to tweak the URL rewrite code above because not every URL will be incoded correct? How will the user access basic pages like home, about, etc..?

I am creating an web application in which there will be flow in the application such that after this page the user will be automatically redirected to the next page as programmed. So there is no need to worry about basic access page as you said.

If you are using Visual Studio, it has a local instance of a basic version of IIS. There's no support for the URL Rewrite module, as far as I know. However, you can also use ASP.NET Routing and add routes to a web form application in the global.asax. I have more experience with the URL Rewrite module. I really have not used the global.asax option, but take a look as this may be helpful for you.

http://msdn.microsoft.com/en-us/library/cc668201.ASPX#adding_routes_to_a_web_forms_application

@JorgeM:
Well Its a good link. But that is totally different from what i need. But anyway thankyou, As per Ketsuekiame answer, I can able to do that in a MVC architecture(Correct me if i am wrong). What are you thinking about that?

Unfortunately I am familiar with web forms, not MVC. I would address this design using the URL Rewrite module with a similar example I posted above. I am not sure what else I can add to give you more guidance on how to resolve this.

The key here is that when a user accesses a URL, the web server needs to know what to do with the request. You have to intercept it somehow and perform some action. URL rewriting handles this very well.

So lets go back to your original post. I assume that what you want is when someone accesses the following URL -->

http://www.mangabooks.com/sdDFREdsfefrvgrwghWr34r

The user is taken to -->

http://www.mangabooks.com/welcome.aspx (but the original URL is displayed in the browser bar)

Then, you want to take the string "sdDFREdsfefrvgrwghWr34r", decode it and then present the user the appropriate view, or send the user to another page. If that is correct, again, the only method I've used is URL Rewriting (in web forms).

@JorgeM,

As per your suggestion I am having a doubt. Consider the following code.

  <rewriter>
    <rewrite url="~/products/books.aspx" to="~/products.aspx?category=books" />
    <rewrite url="~/products/CDs.aspx" to="~/products.aspx?category=CDs" />
    <rewrite url="~/products/DVDs.aspx" to="~/products.aspx?category=DVDs" />
  </rewriter> 

does the user gets the page "~/products/books.aspx" when the following url is typed?

~/products.aspx?category=books"

I Mean,when I type the URL in the address bar like below

www.mangabooks.com/products.aspx?category=books

Does the page

www.mangabooks.com/products/books.aspx

will be accesible?

I see where you have your doubt. Actually, it looks like your thinking is in reverse with regard to URL rewriting.

One of the purposes of URL Rewriting is to provide your users with easy to remember URLs as well as improving SEO (search engine optimization) for your site.

So for example, you would give your users and/or create links on your site such as:

http://www.yourDomain.com/products/books/

If you notice, its a very easy to read URL. No need for file extensions. Anyone seeing this URL knows that the page is related to book products.

With URL rewriting, we can accept this URL from a user and show the content from the page:

http://www.yourDomain.com/products.aspx?category=books

To learn about URL rewriting for ASP.NET web forms, I would start here:
http://www.iis.net/downloads/microsoft/url-rewrite

This is a great web page that I have bookmarked that has common tips and tricks: http://ruslany.net/2009/04/10-url-rewriting-tips-and-tricks/ (i have even reached out to this author on iis.net for help. he's awesome when it comes to the url rewrite module).

@JorgeM,
Thank you. The links are helpful. I am working on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.