Bruce Hunter - 61 - Sep 10, 2014

WebForms Web Application:

For the pages that need to have Authentication cookie. I would just do the following on each page that requires one to be logged in with session/cookie.

    [Authenticate(HtmlRedirect = “login.aspx”)]
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }

Bruce Hunter:

Or this just goes above the login.aspx page code behind.

Bruce Hunter:

I think this is my last hurdle with ServiceStack in a WebForm setup.

Bruce Hunter:

I was looking at the ServiceStack code and I think I have to create a BasePage that ties to the CustomSession that I created etc.

I was looking at ServiceStack.WebHost.IntegrationTests

I guess this is the way to go.

WebForms doesn’t do Filters so that’s not possible. Using ServiceStack.Razor would provide the best integration, Otherwise look at the ASP.NET PageBase used in the ServiceStack.Host.AspNet package:
https://github.com/ServiceStack/ServiceStack/blob/master/NuGet/ServiceStack.Host.AspNet/content/App_Start/PageBase.cs.pp

You would need to do something like:

if (!UserSession.IsAuthenticated)     RedirectToLogin();

Bruce Hunter:

Thanks, that helps. I want to use MVC as I agree with you; more built in features, but the devs I work with do not for lack of knowledge.

I’ll have a look at modernizing this PageBase to see what a good solution would be.

Bruce Hunter:

Funny, this is the same code I found in the ServiceStack.Tests namespace. My CustomUserSession object is actually in the Interface.Session.CustomUserSession location. No need to have 2.

Note: ServiceStack.Razor isn’t or has any dependency on MVC, it’s much simpler with both “No Ceremony Controller-less” Content Pages and Smart View Pages that you’re used to in WebForms as well as MVC model using ServiceStack Services (i.e. no MVC Controller in sight). See http://razor.servicestack.net/ for more details. It just uses @Razor syntax for views.

Bruce Hunter:

Sweet! Thanks for the information. I will take that into consideration. Oh, keep up the good work. Love the product.

Bruce Hunter:

I’m assuming that RedirectToLogin method would just be something I add to do the redirecting to where I want if no Session.

Yeah that’s just a custom method that does the redirect if there’s no authenticated Session.

Also for SS.Razor the EmailContacts and HttpBenchmarks docs have a good walkthrough of using ServiceStack.Razor
https://github.com/ServiceStackApps/EmailContactshttps://github.com/ServiceStackApps/HttpBenchmarks