URL Rewriting, Temporary Solution, ASP.Net 3.5 - c#

We've got a test site hosted only by IP address. We really need to test some functionality that depends on what subdomain someone is using to get to the site. But of course we can't even USE subdomains with an IP only site.
So, one thought I had was that instead of subdomains, we could have the testers open the site with a URL like this: http://192.168.0.1/smith or http://192.168.0.1/jones and I would then redirect them to http://192.168.0.1/default.aspx?site=smith etc...
Our testers are at the client, and asking them to enter in the querystring would be problematic. Plus, I'd really like to get a quick intro into URL Rewriting.
Can anyone give me any idea if what I want to do is possible, and if so, a pointer to some code or explanation or something?
We are using asp.net 3.5 and iis6, I believe.
Thanks for any help!

I wrote up an introduction to URL Rewriting in ASP.NET on my blog, for what its worth. Feel free to post more questions here to clarify any specific issues you have.

this will definitly work in your situation
http://www.urlrewriting.net/149/en/home.html
we have implemented same what you required is, its open source dll and you need to write some rules in web.config, according to your scanario, your rule something like
<add name="index" virtualUrl="^~/(.*)/Default.aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/Default.aspx?site=$1&urw=t" ignoreCase="true"/>

you could possibly change the hosts file on the testing machine to point domains (and subdomains) at that IP, that way you wouldnt have to rely on DNS and could test as if the domains were assigned.
more information here:
http://labnol.blogspot.com/2004/10/tweak-your-windows-hosts-file.html

Using ASP.NET Routing Without
ASP.NET MVC
Using ASP.NET
Routing Independent of MVC
this is part of .Net 3.5 and is the
same mechanism used by MVC
This makes your life easy, due to the fact that everything is held in the HttpContext.CurrentContext.Items[""]
I have adapted this code for a few project where I have an XML configuration file. I then use this file to build the RouteCollection. This code has also been easily extended to handle 301 redirects for SEO.
This method is also loaded once in your AppPool and removes the need to parse xml files and configurations for every call. This so far has been the best solution for me performance wise.
If you need any assistance please let me know. I will gladly lend a hand.
Edit : 13/09/09
I have not run into that problem yet since I usually handle the membership / authentication verification in every page. I usually have a control or method I call on the page to validate/ authorize a user. My clients rarely use the ASP.Net membership, they usually rely on proprietary sub systems which we need to connect to.
I have extended the examples provided in the above links so that I can write one xml routing table which gets loaded when the application starts up or when I force a RouteCollection update.
so far this has proven itself to work pretty well.
this can also allow for a change in routes while the application is running, with no down time.

Related

What would be the best way to generate website from db

We have a lot of red tape to handle before any changes to anything can be made on our servers. Hence I'm looking for ideas and/or suggestions for the below situation.
Must generate html from db (MSSql Server) for a static website hosted on IIS 6/7.
No (external) changes should be necessary on the server side except the ones the application/website makes itself.
I tried markdown and it generates everything nicely but I could not find a way to make the above idea applicable with it. I am willing to put all html code in the db for each individual page but it sounds awkward. Should I go with something ASP.NET'ish or a Windows Service or a standalone app to run at a schedule.
Thanks for the suggestions.
ASP.NET Dynamic Data might be your technology of choice.
http://msdn.microsoft.com/en-us/library/vstudio/ee845452%28v=vs.100%29.aspx
However, my advice is that you'll never be able to solve your problems by something like the above. You need to work out how to do releases more often - maybe start with a CI server and start scripting your releases if you haven't already.

Simplest way to serve dynamic content with .net (& preferably iis) without any form of asp.net / WCF / built in technology

I'm trying to find the simplest way to server content over http (preferably through IIS but if required self hosted is an option). I'm not interested in using any form of web service or asp.net tech for this & am looking for the least overhead as i have no use for the added features.
The closest thing i found to my need is asp.net web api but it's still too featured / HL for me & doesn't really fit my need (i don't want actions mapped to urls, i want to receive the url & handle that myself, i know i could override that but once again it seems like a lot of overhead for nothing).
Just to be clear as i know it will popup : no i don't need any of the added functionality from those Tools including the obvious build in ones (i don't need authentication / security / sessions etc) all i need is
UrlCalled(string url)
{
return ThisReturnsHtmlAndIDoEverythingElse();
}
Can you think of anything that would work? I thought about using http classes to host a server but there i miss out a lot of the functionality of IIS (making sure the website is always up etc).
.Net version is not a problem, it's for hosting on Windows server 2012, even beta versions are fine.
Sounds like a custom asp.net handler could fit you. A handler lets you work at the lowest possible level.
http://msdn.microsoft.com/en-us/library/ms228090(v=vs.85).aspx
In a custom handler you could read disk files (pages) and return them, build custom html strings and return them and do any other tasks you want.
What's more, by registering a handler to a specific custom extension, you could have your own "web execution engine", for example instead of ".aspx" extension, your "pages" could have ".foobar" or any other extension of your choice (including extensionless requests).
In the end rolling my own server with HTTPHandlers was the best compromise i found as i couldn't find a low overhead solution with IIS, ended up serving semi dynamic content faster than iis serves static files so pretty happy about that.

Running MVC and Umbraco 4.7 applications in parallel

We are using Umbraco 4.7.1 and it's very slow sometimes, taking more than 10-14 secs to load certain web pages.
Is it possible to create a new MVC web application and use this to display the slow pages instead of Umbraco? The important thing is that it should run on same web server and should replace a specific path currently existing in Umbraco, e.g. http://127.0.0.1/Product.
Any suggestions how to improve the performance are also welcome.
There are two parts to the answer. Firstly, yes you can. You can host the MVC application as an application within the site in IIS. You will need to ensure that you override all the web.config settings as these settings will be inherited. You will also need to add an the path of your MVC application to the umbracoReservedUrls and/or umbracoReservedPaths appSetting in the Umbraco web.config.
However, the second part of the answer is: don't.
Do not create and host a separate MVC application purely because you have performance issues in your Umbraco application. Figure out what is causing the performance issues and fix it. It sounds like you are possibly making too many calls to the database, or the calls that you are making aren't optimized.
My advise would be to run SQL profiler over the site on these pages and check what is happening. You should then review the indexes on the non-umbraco elements of your database, using views where appropriate, and also review whether you are using appropriate caching.

Simple access control with WIF 4.5

What is for sure, the more I read about WIF, the more I get confused about how to do things.
For something that was supposed to ease things, I can't imagine how it would be without. I guess there's too many scenarios and I have hard time to find the one that fits me.
For some (good for my point of view, but maybe bad) reasons, I want to avoid a official STS (ADFS or ACS) and then write my own to keep things simple!
What I'm looking for is being able to deal with Users (that I'll wrap from an AD identity), Groups of users (custom) and Roles that get users/groups assigned to (custom).
I want to decorate my client side methods with the ClaimsPrincipalPermissionAttribute (or a declarative equivalent) to check if the current user has the required role. I want to be able to use that from a Windows Client application or a WCF Service hosted on IIS/WAS (Net.tcp is my preferred choice of binding).
Some guidance will be greatly welcome as I'm tired to read on an on WIF materials without any improvement of how the solution could be shaped.
Thank you !
So first of all - there is no such thing as a simple STS. I hope you realize that an STS is criticial security infrastructure and probably should not be your first WIF project. If you want to have a look at an open source STS to get some ideas have a look here: http://thinktecture.github.com/Thinktecture.IdentityServer.v2/.
Next authZ happens on the server side (client side is usability). Simply roles checks are rather done with PrincipalPermission. ClaimsPrincipalPermission encourages you to separate service and security code - look up ClaimsAuthorizationManager for more information.

Odd (Slow) Behaviour in ASP.NET

First off I would like to apologize beforehand, in case this turns out to be a really dumb question. I just can't wrap my head around it.
I have a C# ASP.NET website running with .net 2.0
Both on my local machine, as well as on production server it runs terribly slow.
Even if I disable ALL the code, it still runs slow to serve the page.
However, if it is a .ashx, instead of a .aspx it executes immediately; even if it executes the same things.
Any ideas?
Truly appreciated!
if your ashx page loads faster than the aspx, it might be related to the HttpModules or aspx page lifecycle custom code running on your application.
Check if you have anything in the Application_BeginRequest or other events in the lifecycle that could be writing to files (logs), connecting to slow databases or a authentication authority (like AD) that might be going thru the network and taking longer than usual to process.
Disable all the HttpModules in the web.config one by one and test. Check this great article to get more info
Are your .aspx pages defined as content pages for a Master page? Perhaps there is logic being executed in the Master.
Have you tried creating a new, quick Website on your local server to test the speed? Try creating a quick asp.net website and test it on the local server. If this new website goes fast, it may be something within your existing website that you're not aware of.
Is there any difference between the inbuild development server and your iis server?
Could it be a slow javascript? Ajax request? Is botht he asjx and aspx doing the same things?

Categories

Resources