Friday, June 20, 2025

Website admin tool - access rules for files and folders

Access rules are store in web.config for each folder

example like below:-

<?xml version="1.0" encoding="utf-8"?>

<configuration>

    <system.web>

        <authorization>

            <allow roles="Administrator" />

          <deny users="*" />

        </authorization>

    </system.web>

</configuration>

How to download the file using handler in asp.net c# of any format or extension

  public void ProcessRequest(HttpContext context)

  {

    if (context.User.Identity.IsAuthenticated)

    {

      string filename = context.Request.QueryString["File"];

      //Validate the file name and make sure it is one that the user may access

      context.Response.Buffer = true;

      context.Response.Clear();

      context.Response.AddHeader("content-disposition", "attachment; filename=" + filename);

      context.Response.ContentType = "application/octet-stream";

//File(HelloWorld.txt) should be present on server in App_Data folder , otherwise it will show error

      context.Response.WriteFile("~/App_Data/" + filename);

    }

  }

aspx page

<a href="MyFileHandler.ashx?File=HelloWorld.txt">Click Here to Get File</a>

How to download the file using transmitfile function in asp.net c#

 Response.ContentType = "application/pdf";

Response.AppendHeader("Content-Disposition", "attachment; filename=MyFile.pdf");

//MyFile.pdf should be present in Files folder on server. other wise it will show error file not found.

Response.TransmitFile(Server.MapPath("~/Files/MyFile.pdf"));

Response.End();


reference:-https://www.c-sharpcorner.com/UploadFile/afenster/how-to-download-a-file-in-Asp-Net/

why Http Handler are used - Introduction to handler

 Http handlers are used for


Binary files

Dynamic image views

Performance-critical web pages

XML files

Minimal web pages


and these are fast and it only gives minimum response. example when you write  

Response.ContentType = "text/plain";

         //MediaTypeNames.Text.Plain

in aspx page it will give lot of information.

and when you write this in handler it will give only specific information that you want.


Also no return type of processrequest funtion in http handler

you can create other return type function in handler and also create model in handler.

Thursday, June 19, 2025

Computer vs television - difference between computer and television

 Computer is having data and english hindi lanuguage all time. and text is very small


but in television we have visual things , and text is very large if it had