hiding the path of a file on web server - asp.net

I have a webpage that host documents on iis. When linking to those files for examples say I go to
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
I get the file back and have the complete url in the address bar. Is there a way to be able to browser to
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
, and get for example
www.webpage.com/Webdocs/1.pdf
as the url in the browser. My theory was make
www.webpage.com/Documents
a virtual directory, but I am not sure if I would still be able to access my files as
www.webpage.com/Documents/testdocuments/innerfolder/1.pdf
or if I would have to use for example
www.webpage.com/Webdocs/testdocuments/innerfolder/1.pdf
which defeats the purpose really. My ultimate goal is for the physical path of the file to not be visible to the user.
Any ideas would be greatly appreciated.
Thanks,

Since you are looking only to map one path to another you should use IIS url rewriting.
<rewrite>
<rules>
<rule name="Map Docs" stopProcessing="true">
<match url="^Webdocs/([_0-9a-z-]+)" />
<action type="Rewrite" url="Documents/testdocuments/innerfolder/{R:1}" />
</rule>
</rules>
</rewrite>
The other alternative is asp.net url routing. But it would be an overkill for what you need.

Related

Single WebApplication with multiple domain names

For example, I have a Web Application www.mywebsite.com based on classic ASP.NET and IIS 7.5. Now I registered another domain name www.mywebsite.cc. In my Web Application I want to create subfolder /cc and somehow transparently rewrite all requests from www.mywebsite.cc/something to www.mywebsite.com/cc/something. Why I need this? I want both websites to share same static variables, cache, database connections etc. Please point me what technology I must dig in order to implement what I need.
There are a couple of ways to do this, you might try URL rewriting. Your code might look something like this, but you'll need to adjust the line following string: "^something/?$|^something/(.*)$" to contain the proper match code. This should get you started and hopefully someone else will be able to comment on the proper match code.
<rewrite>
<rules>
<remove name="RedirectToUtility"/>
<rule name="RedirectToUtility" stopProcessing="true">
<match url="^something/?$|^something/(.*)$"/>
<conditions/>
<serverVariables/>
<action type="Redirect" url="http://www.mywebsite.com/cc/something/{R:1}"/>
</rule>
</rules>
</rewrite>
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module

Outbound URL Redirect Rule to serve content request from an Azure CDN not working

I wrote a redirect rule that will route client's content requests, to the linked Azure CDN serving my hosted ASP.Net MVC website on an Standard plan.
I tried several iteration of the rule; nothing is working
These are the steps I took to implementation
Create Storage
Create CDN ENDPOINT http:// azxxxxxx.vo.msecnd.net/
Created a subdomain at GoDaddy verified and pointing to azxxxxxx.vo.msecnd.net/
Created a public container using Cloudberry Explorer
Uploaded images blobs to the container and
Tested content availability successfully on the browser at http:// azxxxxxx.vo.msecnd.net/images/test.jpeg
Tested content availability successfully on the browser at https:// storage.blob.core.windows.net/images/test.jpeg
inserted the Rewrite-redirect rule on the site web.config file
<rewrite>
<rules>
<rule name="CDN Redirection" stopProcessing="true">
<match url="^images/(.*)" />
<action type="Redirect" url="http:// azxxxxxx.vo.msecnd.net/images/{R:1}" />
</rule>
</rules>
</rewrite>
......( No using the custom subdomain name yet waiting for propagation)
Save, stop and restart website, clear cache, F12, inspect element .....nothing, content still being pulled straight up from the website
So what am I doing wrong?
Check my website at http://www.ehubcap.net
Thank you
This is a simple rule that is tested and works on Azure Websites:
<rule name="images redirection" stopProcessing="false">
<match url="images/(.*)" ignoreCase="true" />
<action type="Redirect" url="https://double.blob.core.windows.net/images/{R:1}" redirectType="Permanent" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Note, you don't need the ^ in your match pattern.
You can check the result here - check the original page source first - IMG element refers to a local image: http://double.azurewebsites.net/images/some.jpg, which is being redirected by the URL Rewrite to the blob storage (you can redirect to any domain you wish).
Note, however, that URL Rewrite module is dependent on other modules. For best results, the UrlRewrite Module should be the first module to process the result. If you have enabled static and/or dynamic compression to compress the output, the URL rewrite will not work. This is because the default configuration kicks the compression module first, then brings the URL Rewrite module. And the URL Rewrite module cannot read compressed content. Yeah, don't ask me why. So, first disable compression (if you have enabled it) to check the URL rewrite config. Then try to reorder the modules. The simplest would be to first remove them, next add the URL Rewrite and then Compression module.

Denying access to videos and audio directly from browser. Only thru main website

I have been browsing similar questions here but i haven't found my specific scenario.
I have domain.com. I have video.domain.com.
Now, before I continue, I am going to clarify. I am not trying to "protect" my video from being "stolen". This is virtually impossible.
I just don't want direct access to it in order to avoid leeching or downloads. My intention is to "protect" this video from unauthorized access (login and password will do for the website), but of course, if I don't do RTMP (which I intend to do) you got in your browser the full address of the video.
video.domain.com/course/1/Intro.mp4.
and that would not stop you from downloading it directly.
So, I tried a couple of things but didn't seem to work.
First, URL Rewrite. I am using IIS 7. I tried to block any request that {HTTP_REFERRER} was different than domain.com. Didn't work. Yes, it did block me from download it, but that's because my {HTTP_REFERRER} was empty. Which is also empty when domain.com try to access my subdomain. So, it did block the download but also to be able to play it from my website.
So, that, didn't work.
Next, I tried some IP Address Domain and Restrictions but didn't work either.
Has someone be able to do this successfully? I know amazon services are able to do this successfully but I can't think of a way.
Thank you
SOLUTION.
So, at the IIS level, in my videos.domain.com site, I created an URL Rewrite Rule where every request to a MP4 triggers this verification.
No empty Referer (if you call the video from video.domain.com/..../Intro.mp4, then it would not have a Referer).
Match ONLY "http://domain.com". If it doesn't match that, it would not serve the video. It would serve an image saying "Do not steal the videos" :)
Very simple.
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ONLY from DOMAIN.COM" stopProcessing="true">
<match url="(?:mp4)$" />
<conditions>
<add input="{HTTP_REFERER}" pattern="^$" />
<add input="{HTTP_REFERER}" pattern="^http://domain\.com/.*$" negate="true" />
</conditions>
<action type="Redirect" url="http://videos.domain.com/leechingisbad.jpg" appendQueryString="false" redirectType="Temporary" />
</rule>
</rules>
</rewrite>
</system.webServer>

Configure ASP.NET Routing in Web.config

Is there a way to configure ASP.NET routing in the web.config file? I do not need anything fancy. If a user visits /myApp/list, I want to load /myApp/list.html. However, I do NOT want the address bar to change.
Is this possible? If so, how?
The best way is to use UrlRewrite module in IIS: http://www.iis.net/learn/extensions/url-rewrite-module
How you make this rule into web.config after installing UrlRewrite:
<system.webServer>
<rewrite>
<rules>
<rule name="my-first-url-rule" stopProcessing="true">
<match url="^/myApp/list$" />
<action type="Rewrite" url="/myApp/list.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
As of now there is No out-of-the-box way to configure routes in web.config file.
It seems vision was/is to add new routes on Application Start.
This doesn't stop us from creating custom configuration section and reading routes from there.
These are guesses why.
Most of the time, it seems, adding new routes could be prone to introduction of routing bugs and should be followed up with good regression testing. And therefore it probably will be done as part of new product release anyway. Perhaps that could be one the reasons why it's not configurable through configuration file.
Another reason could be that routes rules can be quite complex to put them into xml format - constraints, custom route handlers,etc.

Redirect *.domain.com & domain.com to www.domain.com

I've got an Search Engine Optimisation problem where users are able to access my site by specifying any sub-domain. This is causing duplicate page issues with SEO.
For example if a user mis-types 'www' then posts a link on a forum, google is crawling 'wwww.domain.com'. Furthermore, google is also crawling 'domain.com'.
I need a way of forcing the site to always redirect to 'www.domain.com' regardless of how the user accesses the site.
Is it possible to do this in the web.config file? If not, how else can I achieve this?
Cheers, Curt.
You can do this using the IIS URL Rewrite module. Here's the config to rewrite domain.com to www.domain.com:
<system.webServer>
<rewrite>
<rules>
<rule name="Canonical host name">
<match url="^(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.domain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.domain.com/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
You might need to modify the regex a bit or add a second rule to support rewrite of specific subdomains as well.
Unfortunately URL Rewrite module is not available on IIS6.
If you want to use url rewriting, you could check one of the following:
http://www.isapirewrite.com/ (not free)
http://urlrewriter.net/ (free)
http://cheeso.members.winisp.net/IIRF.aspx (my favourite)
Ah, just did this!
Set the default site to just redirect all calls using URL Redirect to your www.site.com, then create another site with your actual content that binds just to the www subdomain.
This will mean that all traffic will be redirected to the www site if there is no other binding available.
This has worked perfectly for me:
IIS 6 how to redirect from http://example.com/* to http://www.example.com/*
I had to change a bit of the code to get it to work with my Url-Rewriting, but apart from that, spot on!

Resources