locked
Help needed in Authentication with auto post form RRS feed

  • Question

  • User1489758560 posted

    Hello, 

    I have two applications names websitA, WebSiteB. WebsiteA is created on asp.net webform 4.5.1 and WebsiteB created using asp.net core 2.2 razor.  There is a button in websiteA and when hitting the button, It will redirect to WebsiteB. On the button click, along the the redirecturl, am adding querystring which has encrypted username and password. I want to receive this username and password in the WebsiteB and read the query string and based on the authentication, it will be redirect to home page else access denied page will be displayed. I am new to asp.net core 2.2 razor. i am learning using online videos. So far I know creating cshtml page and adding username and  password textbox and firing the form using POST event. But my requirement is, I have to redirect to the page where there should not be any controls and on the load of the page, I have to read the querystring and based on authentication against my database, action will be triggered. How to achieve this. Any sample code will be highly appreciated.

    Wednesday, February 5, 2020 1:20 AM

Answers

  • User475983607 posted

    But my requirement is, I have to redirect to the page where there should not be any controls and on the load of the page, I have to read the querystring and based on authentication against my database, action will be triggered. How to achieve this. Any sample code will be highly appreciated.

    Just add username and password input parameter to the Razor Page OnGet method.

        public class IndexModel : PageModel
        {
            private readonly ILogger<IndexModel> _logger;
    
            public IndexModel(ILogger<IndexModel> logger)
            {
                _logger = logger;
            }
    
            public void OnGet(string username, string password)
            {
                Username = username;
                Password = password;
            }
    
    
            public string Username { get; set; }
            public string Password { get; set; }
        }
    @page
    @model IndexModel
    @{
        ViewData["Title"] = "Home page";
    }
    
    <div>
        Username: @Model.Username
    </div>
    <div>
        Password: @Model.Password
    </div>

    URL to invoke the OnGet contains querystring parameters.

    https://localhost:44393/?username=Hello&password=World

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 5, 2020 11:30 AM

All replies

  • User475983607 posted

    But my requirement is, I have to redirect to the page where there should not be any controls and on the load of the page, I have to read the querystring and based on authentication against my database, action will be triggered. How to achieve this. Any sample code will be highly appreciated.

    Just add username and password input parameter to the Razor Page OnGet method.

        public class IndexModel : PageModel
        {
            private readonly ILogger<IndexModel> _logger;
    
            public IndexModel(ILogger<IndexModel> logger)
            {
                _logger = logger;
            }
    
            public void OnGet(string username, string password)
            {
                Username = username;
                Password = password;
            }
    
    
            public string Username { get; set; }
            public string Password { get; set; }
        }
    @page
    @model IndexModel
    @{
        ViewData["Title"] = "Home page";
    }
    
    <div>
        Username: @Model.Username
    </div>
    <div>
        Password: @Model.Password
    </div>

    URL to invoke the OnGet contains querystring parameters.

    https://localhost:44393/?username=Hello&password=World

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 5, 2020 11:30 AM
  • User1489758560 posted

    thanks a lot. 

    Wednesday, February 5, 2020 6:47 PM