File Download permission control (Asp.net)

Source: Internet
Author: User
File Download permission control (Asp.net)

Post:Andy. mDate:Popularity:55

The author makes a report Presentation website where the reports are stored on the server in Excel format. He or she wants to download the Excel report by the login or authorized person. However, the file download path cannot be hidden, so page control is useless. Recently, when I was studying IIS, I suddenly became very open.

First, edit or modify the Web. config of the website, and add or modify the red area.

<! -- Authentication

This section sets the applicationProgramAuthentication Policy. Possible modes are windows ",

"Forms", "Passport", and "NONE"

"None" does not perform authentication.

"Windows" IIS performs Authentication Based on application settings

(Basic, simple, or integrated windows ). Anonymous access must be disabled in IIS.

"Forms" you provide users with a custom form (web page) for entering creden,, and then

Verify their identity in your application. User creden are stored in cookies.

"Passport" authentication is performed through Microsoft's centralized identity authentication service,

It provides independent logon and core configuration file services for member sites.

-->

<Authentication mode = "forms">

<Forms name = ". aspxuserdemo "loginurl =" login. aspx "Protection =" all "timeout =" 60 "Path ="/"> <credentials passwordformat =" sha1 "/> </Forms>

</Authentication>

<! -- Authorization

This section sets the application Authorization Policy. Allow or Deny Access From different users or roles

Application resources. Wildcard: "*" indicates anyone ,"? "Anonymous

(Unauthenticated) user.

-->

<Authorization>

<Deny users = "? "/>

<! -- <Allow users = "[comma-separated user list]"

Roles = "[list of roles separated by commas]"/>

<Deny users = "[comma-separated user list]"

Roles = "[list of roles separated by commas]"/>

-->

</Authorization>

Then write login. aspx

For Login winners

Formsauthentication. setauthcookie (UID, false );

Formsauthentication. redirectfromloginpage (UID, false );

Open IIS, find your website, right-click, select Properties,-> main directory-> Configuration

Then, select "ing,

Add example.

Now, let's see what you can see when you access the xls file http: // localhost/SMS/1.xlsunder the main site?

Yes, you need to log on. You can download this file only when you enter the logon information!

Yes, that's simple. If role is added, more complex control can be performed.

Welcome to the discussion (maximon@sina.com Wuxi state tax huichun)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.