Rerouting all ASP.NET pages - c#

I am looking to rewrite all ASP.NET pages to a uniform structure. Something like:
/Content1/Page1.aspx -> /Page1
/Content1/Page2.aspx -> /Page2
/Content2/Page3.aspx -> /Page3 (note
different sub-dir)
/xyz/Page4.aspx -> /Page4
Is this possible?
URL Rewriting seems interesting... Will it also comply with my web.config security rules (ie. address access only to /Content2/Page5.aspx should remain in force when browsing to /Page5).

If you're using IIS 7+, you can use the IIS URL Rewrite Module from Microsoft (link).
If you're using IIS 6, take a look at ISAPI Rewrite. I used it a little and it seemed to work pretty well.

Have you looked into URLRewriting? I suppose you could do it with URLRouting as well, but I'll let someone else answer that route.
EDIT:
Another option is that if you know the EXACT file path for each file, you can hard code each path using URLMappings

Related

To Change the Jquery version of a ASP.NET App

Currently I need to change the jquery version from 2 to 3 of an ASP.NET that is running on an IIS Server.
A vulnerability scanned our server and it created a incident to solve.
I found the file "<IIS_Directory>/Views/Index.cshtml" that has the Javascript references.
#Scripts.Render("~/scripts/vendor")
When I access from a browser I get several scripts instead of ' #Scripts.Render("~/scripts/vendor")'
How do I change the result of the '#Scripts.Render("~/scripts/vendor")' in a production environment?
Constraints
I Only have the publish folder.
At the moment I don't have the code source. until I have the code source I have to apply a patch.
I think you can't do this without source code.
The JQuery library is imported into the BundleConfig.
I think it may be a solution, although not optimal, replace under Scripts JQuery's files with same file of version 3 and give it the same names.
#Scripts.Render("~/scripts/vendor")
Is used to render a script tag (you said there was more than 1 so the bundler must be in debug mode) but the configuration of that bundle will be done in .NET code so you cannot realistically change that without the source code.
Perhaps you could update the actual jQuery source files (using the same file name) on the server and you may get lucky that nothing being used by the other scripts uses anything that has been removed in the move to version 3.
The only way to do it properly and not risk breaking the site is to do it in a proper development environment with the full source code and a proper regression test of all of the sites features.

How do I get the generated domain name for local URL's for a Windows 8 app?

I have a Windows 8 app that downloads the online assets, unzips them into the LocalState folder, and accesses that content when the user is offline. I use a custom IUriStreamResolver to provide the content. The local URL might look like this:
ms-local-stream://package-name_application-key/.../.../
The part I'm after is the application-key. While the package-name is in the Package.appmanifest, the application-key is not. I've also verified the package-key is not part of the LocalState path. I'm wanting to use WebView.BuildLocalStreamUri and it requires the contentIdentifier, this is documented as the concatenation of the package-name and application-key.
I've done quite a bit of digging through the API's via the Object Browser, and of course I've pretty much exhausted Google and DuckDuckGo (love that search engine BTW), and they've not provided any fruit.
Does anybody know how I can get at that key the app generates and uses for this?
Apparently it doesn't actually matter what the value is. It has no bearing on the URL that is formed. I wanted to answer this for the next person trying to use this method. It just cannot be null or an empty string.

Override ApplicationRoot in ASP.NET

I'm messing around with the cheapest .NET Arvixe server for learning purposes and try to install an application (Umbraco in this case) in a particular way.
Arvixe count's subdomains as websites, which means I'm currently limited to 6 of them. With some clever URL Rewrite trickery, I managed to setup the following structure.
FTP-folder:
> mydomain.com
>> wwwroot
>> subdomains
>>> subdomain1
>>> subdomain2
>>> etc.
wwwroot is the main website, under which I added Virtual Directories for each subdomain. So if in the browser you would go to http://www.mydomain.com/subdomain1, you'll end up seeing whatever app is installed under subdomains/subdomain1.
After applying some URL Rewrite, I can go to http://subdomain1.mydomain.com, and it will show me the same content as if I would go to http://www.mydomain.com/subdomain1
Now this is where the problem I'm experiencing begins.
Whenever in code I would do a relative path (eg. ~/Blog/Test/123.aspx), it will resolve to http://subdomain1.mydomain.com/subdomain1/Blog/Test/123.aspx. This all still works, as the everything is still under a single website, I just don't want the /subdomain1/ part in the URL. If I manually remove the /subdomain1/ part, the page also render fine due to my rewrite rules.
After some searching I found out that internally, whenever code has to resolve a ~/-url, it will use HttpRuntime.AppDomainAppVirtualPath for that.
How can I trick ASP.NET into thinking it's hosting under the Virtual App Path of '/' rather than '/subdomain1/'?
I have tried a few things which do not work (or I just did it wrong):
- Thread.GetDomain().SetData(".appVPath", "/");
- Make a VirtualPathProvider
In all cases, it will throw exceptions.
Is hosting under it's own website really the only solution (which means I have to upgrade the account)?
I tried all kinds of hacks by means of Reflection, so it's certainly not possible by normal means. In the end I got as far as confusing IIS, as the ApplicationRoot wasn't overwritten on all locations. So I gave up, it's not possible.

Making my application open/called from a browser with a custom protocol

Im making a small application that opens my own files that contains log data. I have a log viewer for these files but would like to link to them from my intranet. Im looking to create an url that looks like this:
log://log/id
Where log and id is the path to the file from the net to open. How do I accomplish this. Should the changes be in my application or in the IIS that serves the page (and thus the link)?
cheers,
I believe this can be done fairly easily for IE, but I am not sure about other browsers.
See this and this on SO.
To implement a custom scheme is probably going to require installation/registration at the OS level, for example in the registry for windows (allow user-level may suffice). For the sake of simplicity, http would probably the sensible default unless you really, really need something custom.
MSDN discusses this for windows here: http://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx

Minifying and combining files in .net

I am looking at implementing some performance optimization around my javascript/css. In particular looking to achieve the minification and combining of such. I am developing in .net/c# web applications.
I have a couple of options and looking for feedback on each:
First one is this clever tool I came across Chirpy which via visual studio combines, minifies etc -> http://chirpy.codeplex.com/ This is a visual studio add in but as I am in a team environment, this tool isnt ideal.
My next option is to use an Msbuild task (http://yuicompressor.codeplex.com/) to minify the files and also combine them (maybe read from an xml file what needs to be combined). While this works for minifying fine, the concern I have is that I will have to maintain what must be combined which could be a headache.
3rd option is to use msbuild task just for the minifying and at runtime using some helper classes, combine the files on a per page basis. This would combine the files, give it a name and add a version to it.
Any other options I could consider? My concern with the last option is that it may have performance issues as I would have to open the file from the local drive, read its contents and then combine the files. This is alot of processing at run time. I was looking at something like Squishit - https://github.com/jetheredge/SquishIt/downloads This minifies the files at run time but I would look at doing this at compile time.
So any feedback on my approaches would be great? If the 3rd option would not cause performance issues, I am leading towards it.
We have done something similar with several ASP.NET web applications. Specifically, we use the Yahoo Yui compressor, which has a .NET library version which you can reference in your applications.
The approach we took was to generate the necessary merged/minified files at runtime. We wrapped all this logic up into an ASP.NET control, but that isn't necessary depending on your project.
The first time a request is made for a page, we process through the list of included JS and CSS files. In a separate thread (so the original request returns without delay) we then merged the included files together (1 for JS, 1 for CSS), and then apply the Yui compressor.
The result is then written to disk for fast reference in the future
On subsequent requests, the page first looks for the minified versions. If found, it just serves those up. If not, it goes through the process again.
As some icing to the cake:
For debug purposes, if the query string ?debug=true is present, the merged/minified resources are ignored and the original individual files are served instead (since it can be hard to debug optimized JS)
We have found this process to work exceptionally well. We built it into a library so all our ASP.NET sites can take advantage. The post-build scripts can get complicated if each page has different dependencies, but the run-time can determine this quite easily. And, if someone needs to make a quick fix to a CSS file, they can do so, delete the merged versions of the file, and the process will automatically start over without need to do post-build processing with MSBuild or NAnt.
RequestReduce provides a really nice solution for combining and minifying javascript and css at run time. It will also attempt to sprite your background images. It caches the processed files and serves them using custom ETags and far future headers. RequestReduce uses a response filter to transform the content so no code or configuration is needed for basic functionality. It can be configured to work in a web farm environment and sync content accross several servers and can be configured to point to a CDN. It can be downloaded at http://www.RequestReduce.com or from Visual Studio via Nuget. The source is available at https://github.com/mwrock/RequestReduce.
have you heard of Combres ?
go to : http://combres.codeplex.com and check it out
it minifies your CSS and JS files at Runtime meaning you can change any file and upload it and each request the client does it minifies it.
all you gotta do is add the files u wanna compress to a list in the combres XML file and just call the list from your page / masterpage.
if you are using VS2010 you can easily install it on your project using NuGet
here's the Combres NuGet link: http://combres.codeplex.com/wikipage?title=5-Minute%20Quick%20Start
I did a really nice solution to this a couple of years back but I don't have the source left. The solution was for webforms but it should work fine to port it to MVC. I'll give it a try to explain what I did in some simple step. First we need to register the scripts and we wrote a special controller that did just that. When the controller was rendered it did three things:
Minimize all the files, I think we used the YUI compression
Combine all the files and store as string
Calculate a hash for the string of the combined files and use that as a virtual filename. You store the string of combined files in a cached dictionary on the server with the hash value as key, the html that is rendered needs to point to a special folder where the "scripts" are located.
The next step is to implement a special HttpHandler that handles request for files in the special folder. When a request is made to that special folder you make a lookup in the cached dictionary and returns the string bascially.
One really nice feature of this is that the returned script is always valid so the user will never have to ask you for an update of the script. The reason for that is when you make a change to any of the script files the hash value will change and the client will ask for a new script.
You can use this for css-files as well with no problems. I remebered making it configurable so you could turn off combine files, minimize files, or just exclude one file from the process if you wanted to do some debugging.
I might have missed some details, but it wasn't that hard to implement and it turned out very well.
Update: I've implemented a solution for MVC and released it on nuget and have the source up on github.
Microsoft’s Ajax minifier is suprisingly good as a minification tool. I wrote a blog post on combining files and using their minifier in a javascript and stylesheet handler:
http://www.markistaylor.com/javascript-concatenating-and-minifying/
It's worthwhile combining the files at run time to avoid having to synchronise new versions. However, once they are programmatically combined, cache them to disk. Then the code which runs each time the files are fetched need only check that the files haven't changed before serving the cached version.
If they have changed, then the compression code can run as a one-off.
Whilst there will be a slight performance cost, you will also receive a performance benefit from fewer file requests.
This is the approach that the Minify tool uses to compress JS/CSS, which has worked really well for me. It's Linux/PHP only, but you might get some more ideas there too.
I needed a solution for combining/minifying CSS/JS on a .NET 2.0 web app and SquishIt and other tools I found weren't .NET 2.0-compatible, I created my own solution that uses a syntax similar to SquishIt but is compatible with .NET 2.0. Since I thought other people might find it useful I put it up on Github. You can find it here: https://github.com/AlliterativeAlice/simpleyui

Categories

Resources