Archief

Dev

Combining Classic ASP and .NET MVC3

There’s this old-old-old website that I want to give a little upgrade. It’s written in classic ASP (remember “on error resume next”?) and has a nice content management system. I’m not planning on re-writing the whole thing, but just to make some tweaks.

First thing I wanted to do was upgrade to .net 4 and .net mvc3. I’ve allways hosted my sites at Vevida, and they’ve never let me down. This time they moved my website to a different server (took about 20 minutes) and then helped me configure the whole thing. All I have is FTP access and the CMS was in a protected folder so your browser asked a username/password to enter it. In .net 4 this isn’t possible anymore (apparantly) so I created my own authorization using FormsAuthentication:

<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx" defaultUrl="Members" />
  </authentication>
  <authorization>
    <allow users="?" />
  </authorization>
</system.web>
<location path="cms">
  <system.web>
    <authorization>
      <deny users="?" />
      <allow users="*" />
    </authorization>
  </system.web>
</location>

And then the login logic using a normal .aspx file:

var username = Request.Form["username"];
var password = Request.Form["password"];

if (username == "specific" && password == "credentials")
{
  FormsAuthentication.RedirectFromLoginPage(username, true);
}

That’s easy! Everything’s up-and-running again, and now I can start using .asp and .aspx and .cshtml files next to eachother :)

#mvc #.net #classic asp