Showing posts with label authentication. Show all posts
Showing posts with label authentication. Show all posts

12 September 2022

ASP.NET Core disable authentication in development environment

    You can bypass authorization in development environment by applying AllowAnonymousAttribute() to your endpoints. as below code 


 public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

        {

           //-----------------------

            app.UseRouting();

            app.UseEndpoints(endpoints =>

            {

                if (env.IsDevelopment())

                    endpoints.MapControllers().WithMetadata(

                        new AllowAnonymousAttribute());

                else

                    endpoints.MapControllers();

            });

        //---------------------------

          }

27 February 2014

Authentication Using XML

How to make users in XML File and authenticate them..
Solution:
create a xml file as

<mydata>
<tb>
<user>admin</user>
<pass>admin</pass>
</tb>
<tb>
<user>admin1</user>
<pass>admin1</pass>
<tb>
<tb>
<user>admin2</user>
<pass>admin2</pass>
<tb>
</mydata>


Add two Text Boxes on Design page with ids TextBox1 and TextBox2 
Add a label with id Label1
Add a button
double click on button
and write following code in button click event

//code to authenticate user
String pt = Server.MapPath("XMLFile.xml");//
DataSet ds = new DataSet();
ds.ReadXml(pt);
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = "user='" + TextBox1.Text+"'";
if (dv.Count == 0)
Label1.Text = "Wrong User";
else
{
if (dv[0][1].ToString() == TextBox2.Text)
FormsAuthentication.RedirectFromLoginPage(TextBox1.Text, false);
else
Label1.Text = "Wrong Password";
}