Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8789413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:23:55+00:00 2026-06-13T22:23:55+00:00

Login.cshtml …. <form action=/auth/credentials> <div> <span>User Name</span> <input name=userName type=text/> </div><div> <span>Password</span> <input name=password

  • 0

Login.cshtml

....
<form action="/auth/credentials">
    <div>
        <span>User Name</span>
        <input name="userName" type="text"/>
    </div><div>
        <span>Password</span>
        <input name="password" type="password"/>
    </div><div>
        <input name="RememberMe" type="checkbox" checked value="true"/>
        <span>Remember me</span>
    </div><div>
        <button class="login">Sign in</button>
    </div>
</form>
....

LoginService.cs

[DefaultView("login")]
public class LoginService : BaseService {
    public object Get(Login req) {
        return new LoginResponse() { UserSession = base.UserSession };
    }
}

BaseService.cs

....
public CustomUserSession UserSession {
    get {
        return SessionAs<CustomUserSession>(); // **** Error here ****        
    }
}
....

Error Message at SessionAs<CustomUserSession>();

InvalidCastException was unhandled by user code

Unable to cast object of type ‘ServiceStack.ServiceInterface.Auth.AuthUserSession’
to type ‘MyProject.CustomUserSession’.

I have a simple html form in login.cshtml to test out the credentials auth feature. The code is mimicking the credential auth feature part of SocialBootstrapApi demo project.

Before I updated SS from NuGet: (packages from about 40 days ago)

If the html form has RememberMe div, SessionAs<CustomUserSession>(); would hit the InvalidCastException error. Otherwise it works fine with just UserName and Password divs in it.

After I updated SS from NuGet: (packages updated today 4th Nov v3.9.25.0)

SessionAs<CustomUserSession>(); always hits the InvalidCastException error even when the html form just have UserName and Password divs in it.

I’m not sure what I have done wrong in the casting process. Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:23:56+00:00Added an answer on June 13, 2026 at 10:23 pm

    What does your Auth Registration look like?

    This is what the AuthConfig of the SocialBootstrapApi project looks like:

    Plugins.Add(new AuthFeature(
        () => new CustomUserSession(), //Use your own typed Custom UserSession type
        new IAuthProvider[] {
            new CredentialsAuthProvider(),              //HTML Form post 
            new TwitterAuthProvider(appSettings),       //Sign-in with Twitter
            new FacebookAuthProvider(appSettings),      //Sign-in with Facebook
            new DigestAuthProvider(appSettings),        //Sign-in with Digest Auth
            new BasicAuthProvider(),                    //Sign-in with Basic Auth
            new GoogleOpenIdOAuthProvider(appSettings), //Sign-in with Goolge OpenId
            new YahooOpenIdOAuthProvider(appSettings),  //Sign-in with Yahoo OpenId
            new OpenIdOAuthProvider(appSettings),       //Sign-in with Custom OpenId
        }));
    

    The new CustomUserSession() is what tells ServiceStack to use a Custom Session and not the built-in default AuthUserSession.

    And what CacheClient are you using?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In LogIn method I have: FormsAuthentication.SetAuthCookie(model.User, false); and to get name of this user
I want a login form on my home page. In index.cshtml I have this:
Login Form: $authAdapter = Zend_Registry::get('authAdapter'); $authAdapter ->setIdentity($formData['email']) ->setCredential($password) ->setCredential(1); Bootstrap: protected function _initAuth(){ $this->bootstrap('db');
My login form is located at /account/login . GET requests to this URL cause
The below binds the login event to a div. If I click it, I
I had a login page. once user successfuly logged in, they can view and
I'd like to set my web.config file to redirect to login.cshtml if a cookie
I want to build a login form that displays in a sidebar across every
I have a layout page with the following _app.cshtml <div id=top_right> @{ Html.Partial(_LogOnPartial); }
In ASP.NET MVC, I have a main standard form that posts to an action,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.